修改npm -g 无法正常工作

  • 检查npm包是否真正全局安装

    npm list -g --depth = 0
    
  • 接下来检查npm全局保存路径

    npm bin -g
    #output most probably but even if not don't worry till now
    /home//node_modules/.bin
    
  • 修改全局npm包的路径,在这不会篡改默认文件权限,而是通过创建新的配置文件来更改目录本身

    mkdir~ / .npm-global 
    npm config set prefix`~ / .npm-global` 
    export PATH =〜/ .npm-global / bin:$ PATH 
    source~ / .profile 
    npm install -g 
    
  • 手动修改.profile文件

    vim .profile
    

    手动添加下面一行到这个文件中

    export PATH =“$ PATH:$ HOME / .npm-global / bin”
    
  • 重启bash_profile

    source .bash_profile
    

你可能感兴趣的:(修改npm -g 无法正常工作)