For details about how to use NVM to manage different node versions in mac, nvmnode
Preface
Before starting the text of this article, we suggest you read this article: http://www.bkjia.com/article/73424.htm. this article details the use of nvm or n in node.js for version control and nvm installation of node. after the js version, restart the terminal node, and the npm environment variable becomes invalid. Now, let's start with the text below:
Usebrew install nvmThe nvm installed cannot be correctly enabled due to different installation paths. Recommendedbrew uninstall nvmAfter uninstalling the SDK, you can use the solution in this article to reinstall it.
Uninstall the node/npm that has been installed to the global environment
If you have downloaded the node installation package from the official website, the package is automatically installed in the global directory.
The node command is in the/usr/local/bin/node directory, and the npm command is in the global node_modules directory. The specific path is/usr/local/lib/node_modules/npm.
After nvm is installed, it is best to delete the installed node and global node modules first:
Npm ls-g -- depth = 0 # Check the global modules that have been installed, to delete these global modules and then reinstall sudo rm-rf/usr/local/lib/node_modules according to different node versions # Delete the global node_modules directory sudo rm/usr/local/ bin/node # Delete nodecd/usr/local/bin & ls-l | grep ".. /lib/node_modules/"| awk '{print $9}' | xargs rm # Delete the soft chain registered by the global node Module
Manage through nvm
Scenario: if a group of colleagues use node 5.7.0, and node 7.2.0 is installed on the local machine, how can they be compatible?
Use nvm for management.
- Use Homebrew Security nvm
- Use nvm security Node. js
- Using nvm does not bother cutting the Node. js version
Install nvm
brew install nvm
Enable nvm
source $(brew --prefix nvm)/nvm.sh
Or:
echo "source $(brew --prefix nvm)/nvm.sh" >> .bash_profile. ~/.bash_profile
Use nvm security Node. js
nvm ls-remote
View available versions:
v0.10.20v0.10.21
Installation:
nvm install <version>
For example:
nvm install v5.7.0
And
nvm install v7.2.0
Using nvm does not bother cutting the Node. js version
Nvm installs node versions under/usr/local/opt/nvm. Let's take a look at what things have been put under the project:
$ ls /usr/local/opt/nvmINSTALL_RECEIPT.json LICENSE.md alias bin nvm.sh v5.7.0 v7.2.0
We can find two versions of nvm security, in fact, v5.7.0 and v7.2.0 are set up in the nvm category to store node binary classification separately. In addition, nvm will insert the specified version of the project at the beginning of your $ PATH. Through this method, you will use the specified version when using the node command.
Check whether the PATH value is correct:
$ echo $PATH/usr/local/opt/nvm/v5.7.0/bin: ...
View the current available version
nvm ls
Switch version:
nvm use <version>
For example
nvm use --delete-prefix v5.7.0
You can also click here to download the complete version:
$ nvm use --delete-prefix 5.7Now using node v5.7.0
Switch to another version:
$ nvm use --delete-prefix 7Now using node v7.2.0
However, if you open another shell window and access nvm, the current version is blank:
$ nvm ls v0.10.24 v0.11.10current:
This is because the nvm use command will only take effect in the previous shell, when you open a new shell, you will find that the value of $ PATH does not contain the node category set only after the new shell is created.
To solve this problem, we use
$ nvm alias default <version>
To set the node version for a specific deployment:
$ nvm alias default 5.7.0default -> 5.7 (-> v5.7.0)
At this time, open another shell window to directly use the node version you have set.
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.