Brief introduction

NVM: Node version manager that allows quick switching between multiple Node versions on the same device. NRM: NPM source manager that allows quick switching between NPM sources.

reinstall

Previously: The local environment has an NVM that failed to install and a node that was installed separately.

1. Delete the local NVM and Node versions

NVM node (brew installation) : brew uninstall node Node (official website installation) : sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
Copy the code

2. Delete the$NVM_DIR

You can check the following directories

~/.zshrc
~/.bash_profile
~/.bashrc
...
Copy the code

After the deletion, restart the terminal or run the source ~/. ZSHRC command to make the environment variables take effect. To check whether the vm is successfully deleted, run the echo $NVM_DIR command

3. Install the NVM

Follow the instructions on the official website: github.com/nvm-sh/nvm

4. Set the default Node version

Using the official installation method, you can now use NVM to download/switch between different versions of Node. To avoid using NVM use [version] to set the version, you can set a default version:

nvm aliasThe default v8.9.1Copy the code

5. Global installation when using NVM

Because NVM is used and the global installation path is inconsistent with the default global installation path, the global installation package cannot be found. Therefore, you need to set the global folder (note that the version number is replaced by the current version) :

npm config set prefix $NVM_DIR/ versions/node/v8.9.1Copy the code

In this case, the global installation packages of different Versions of Nodes are not shared. Therefore, the global folder path of each version must be set separately.