This article will cover switching between multiple Node.js versions on Windows and Mac.
1. Using NVM in Windows (NVM-Window)
2. In Mac, NVM and N are used
Note: The NVM address for Windows is different from that for MAC
First, Windows system
What is NVM?
NVM is a simple bash script that manages multiple existing versions of Node.js on your system
The configuration steps
- Uninstall the original version of the system node (also can not uninstall, I think or uninstall it, so as not to have a conflict. I did anyway);
I won’t go into details about uninstall, but you can uninstall it in the control panel’s programs and functions.
- Go to Github and download the NVM package
Download: github.com/coreybutler…
Note that the best installation path is C:\ NVM. The default path will cause problems when switching node versions.
Also, after a successful installation, system variables are automatically configured. Don’t worry about it here, just know that this is the case, so that you don’t want to change the environment variable in the future.
Take a screenshot:
NVM_SYMLINK: node installation directory
nvm node_mirror https://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/
Copy the code
A map on cutting
This step is optional. The purpose of the configuration is to switch the NPM image to taobao image, which can improve the download speed. (Just like the rush)
Next verify that the installation is successful
Enter: NVM in CMD if the image below appears successfully
To install Node, you need to know which versions are available, otherwise you will get an error.
You can see it here: github.com/coreybutler…
1. Github takes a long time to open. The version above is not up to date
You can also use the command: NVM list available
(1) I use version 10.13.0 as an example
Note: It’s important to use the NVM use command immediately after installation, otherwise you won’t be able to use the Node version. (This is a pit, MD, wasted my whole morning.)
If you cannot change the version, uninstall the version with NVM uninstall 10.13.0 and reinstall it.
(3) Use the NVM list to check all downloaded versions of Node and which version is currently available (10.13.0).
Some commonly used NVM commands
NVM install [arch] : This can be the Node.js version or latest stable version. (Optional [ARCH]) Specifies whether to install the 32-bit or 64-bit version (the default is System ARCH). Set [Arch] to all to install the 32 – and 64-bit versions.
NVM list [available] : lists installed Versions of Node.js. Optional available, displays a partial list of downloadable versions. This command can be abbreviated to NVM ls [available].
NVM uninstall: Uninstalls the specified nodeJS version.
NVM use [version] [arch] : Switches to using the specified NodeJS version. 32/64 bit [ARCH] can be specified.
There are a few other commands that don’t give a single example
2. Mac system
Either NVM or N should be installed on the MAC system
For the first n
Here are three installation methods (just choose one of them)
(1) If you already have Node on your MAC, use the NPM command to install it
npm install -g n
Copy the code
After installation, cache version N to the node subdirectory n/versions N_PREFIX in the directory specified by the environment variable. The default value is /usr/local. The active Node version is installed directly in N_PREFIX.
To avoid the need for sudo’s N and NPM global installations, it is recommended that you either install to your home directory N_PREFIX or take ownership of the system directory:
# make cache folder (if missing) and take ownership
sudo mkdir -p /usr/local/nsudo chown -R $(whoami) /usr/local/n
# take ownership of node install destination folders
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share
Copy the code
(2) If you don’t have Node, you can install it in another way
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
bash n lts
# Now node and npm are available
Copy the code
(3) Use a third party installation
curl -L https://git.io/n-install | bash
Copy the code
Since I already have Node, I installed it the first way.
- NPM install -g n
- Check whether the installation is successful n –version
In this case, use sudo n 10.13.0
The command format is n node-version
Example: n 10.13.0 Installation 10.13.0 n latest installation official release n stable Installation official release n LTS Installs the latest official LTS version
My Mac, all already installed version of node storage path: / usr/local/n/versions/node
- Switching node Versions
To perform first n
There are three solutions to this problem:
If you want to uninstall a node version, just go to rm 10.13.0.
Finally some classmates have not make the switch, I haven’t met, but I’m try to see this in some posts, recommend a: blog.csdn.net/ruffaim/art…
I’ll update this post if I run into problems like this in the future and talk about using NVM on Mac
In general, it is not much different from using NVM under Windows
Do not ask me why, I do not know, there is a large chance of problems
Here is the uninstall Node command
-g --depth=0 Sudo rm -rf /usr/local/lib/node_modules # delete the global node_modules directory sudo rm / usr/local/bin/node # delete node CD/usr/local/bin && ls -l | grep ".. / lib/node_modules/" | awk '{print $9}' | xargs rm # delete global registration of soft chain node moduleCopy the code
After the NVM installation is a little different, directly from the command line type the following command
curl -o- https:/ / raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
Copy the code
If the command is not found, the installation failed. If the command is not found, the installation failed
Add the following code to the.bash_profile file to configure the environment variables.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Copy the code
Save the file directly after editing.
Then enter source. bash_profile to update the configured environment variables.
If you don’t have this file, you can create one. Refer to the learning article: blog.sina.com.cn/s/blog_8444…
Some commonly used NVM commands
NVM install stable // Installs the latest version
Nodenvm install [Node version] // Install the specified version
Nodenvm use [Node version] // Switch to a node of the specified version
NVM alias default [Node version] // Set the default version
Well, finishing a day, finally finished, I can only say that are pits ah, wish all students this life no bug
Little white one, don’t spray if you don’t like it. If there are mistakes or improper place, but also please big guy correct.