修改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/<user>/node_modules/.bin
    
  • 修改全局npm包的路径,在这不会篡改默认文件权限,而是通过创建新的配置文件来更改目录本身

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

    vim .profile
    

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

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

    source .bash_profile
    
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容