Global Node modules not installing correctly. Command not found

前端 未结 9 1044
北荒
北荒 2020-11-29 20:26

I am having a problem installing global node modules and everything I find online says the solve is just adding -g. Which is not the problem. I believe it\'s a linking issue

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 20:37

    I do not ever install any npm stuff, via sudo! I have my own reasons, but I just try to keep things simple, and user based, since this is a user development world, and not everyone has root access, and root/sudo installing things like this just seems to clutter up things to begin with. After all, all developers should be able to follow these instructions, not just privileged sudo users.

    This particular system is a RHEL7 accessed via SSH:

    Frequently one needs various versions of node, so I use NVM https://github.com/creationix/nvm

    So with that said, I can show you a working example for -g global installs, using NVM, NPM, and node paths not using root.

    set your prefix for .npm-packages if it isn't already. (note, thats a hyphen, not an underscore)

    nvm config ls
    prefix = "/home//.npm-packages"
    

    Then adjust your ~/.bash_profile or .bashrc if you prefer readup on why and which here, with the following information.

    #PATH EXPORTS
    NODE_MODULES=$HOME/.npm                                          
    NPM_PACKAGES=$HOME/.npm-packages/bin                           
    export PATH=$PATH:$HOME/bin:$NODE_MODULES:$NPM_PACKAGES         
    
    #NVM ENABLE                                                 
    export NVM_DIR="$HOME/.nvm"                                   
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm 
    

    That pretty much covers all paths. For e.g., if you install gulp like this npm install -g gulp it symlinks in ~/.npm-packages/bin (note thats a hyphen, not an underscore). (no need for gulp-cli, or gulp-cl)

    You can pretty much replace/comment-out all other node path exports. You can put this path info below any other path info you already have, safely, without it overwriting that stuff.

提交回复
热议问题