Modifying $PATH variable

后端 未结 3 744
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-08 14:16

Trying to install node.js.

Did brew install node

It seems to have worked.

However, received this message upon its completion

相关标签:
3条回答
  • 2021-02-08 14:29

    In PATH ORDER IS IMPORTANT. So anything before desired npm version will still cause problems.

    #adding in first place of the path, before anything else
    export PATH=/usr/local/bin:otherPathEntries:$PATH
    

    assuming that version of npm You want is in /usr/local/bin, to check all use 'which -a npm'

    0 讨论(0)
  • 2021-02-08 14:35

    The cleanest solution is adding the following between the two lines you posted:

    export PATH="/usr/local/share/npm/bin:$PATH"
    

    That way everything stays readable and you prepend it to PATH just like the program suggested it. And if you ever want to undo the change you just remove that line instead of editing a possibly long line.

    0 讨论(0)
  • 2021-02-08 14:46

    Short answer, do this (notice the additional colon I inserted):

    export PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

    The $PATH environment variable is colon separated list of directories to look in if you want to run a command without a fully qualified path (e.g. running npm instead of having to type /usr/local/share/npm/bin/npm).

    You can try this from a terminal before actually saving the change in bash_profile. If everything is good, which -a npm will show you all fully qualified path(s).

    UPDATE

    It is not necessary to modify the $PATH variable in order to use npm. What homebrew install recommends instead is to add the directory where npm-installed binaries are stored to the $PATH variables, so its more convenient to use them from the command line later on.

    Node modules like phantomjs, phonegap, express, etc. provide binaries which after the change are available on the command prompt without having to type the full path.

    0 讨论(0)
提交回复
热议问题