Guide to install nvm and n anti-pit under mac

Posted May 27, 20202 min read

Since the latest version of npm is required to download the webpack4 package, but the 6.4.1 version of npm needs to be retained at the same time, I checked the advantages and disadvantages of the two methods nvm and n, and decided to use the n command

So I installed n globally and installed a stable version

npm install -g n

sudo n stable

Then I sent me a wrong choice ... After the command execution was completed, I began to test whether the version switch can be used. After executing the 10.15.3 command, I reported a lot of errors, meaning that There is no permission to change, I execute the command again to switch to another version, it is still reported this error, I searched a lot of solutions on the Internet and the netizens suggested not to use the n command, this is too pit, the final solution can only be I re After installing Node 10.15.3 version again, I also recommend that you do not use n to manage your Node.

Without the n command, I can only choose the second method:nvm, the installation method is very simple, click the link below github

This link is the address of nvm's warehouse on github, which describes how to install nvm and how to solve the situation that may be encountered.

Copy the following command to the command panel to execute

curl -o- | bash

After the successful installation, close the current command panel. If you do not want to close your new command panel, this step must be done, otherwise the nvm command will only report that the command does not exist.

Type nvm in the newly opened command panel and press Enter to test whether this command can be used

The next step is to install the version

nvm install stable //Install stable version

nvm install 10.15.3 //Install the version to be retained

Execute after the two versions are installed

nvm ls //View the list of installed versions

Found nvm set the latest version as the default version, if you want to modify, execute

nvm alias default 10.15.3 //10.15.3 is the version number, you can replace it with any version number you want to set

Execute nvm ls again and found that the setting is successful

Next, I started to step on the pit. I executed nvm use 10.15.3 and then executed node -v to see that the current version has indeed become 10.15.3. So I started the previous project(the dependency of node \ _modules is 10.15. 3 corresponding to the 6.4.1 npm version), and found that the compilation error, so I immediately entered node -v in the current project directory, found that the version is actually 12.14.0, I seem to understand what, so I am in the current project Execute nvm use 10.15.3 under the path and start the project and the compilation is successful. This is the pit. I have used the nvm command to set 10.15.3. As the default version, but the node version under my project path still stays at 12.14.0 , So friends must first check whether the node version under their project path is consistent with the project's node \ _modules.