Detailed explanation of nvm (mac environment nvm installation steps and stepping on the pit problem)

1. Definition

        nvm, the full name of Node Version Manager, is node version control; it is a command-line application that can help you quickly update, install, use, and uninstall the global node.js version of the machine.
        Sometimes, we may be developing multiple projects at the same time, and the node versions used by multiple projects are different, or we need to use the latest node version for experimentation and learning. In this case, it will be very troublesome to maintain multiple versions of node, and nvm was created to solve this problem. It can switch between multiple node versions on the same computer. And this is where the value of nvm lies.

Usage scenario : When you develop two or more node projects at the same time, and the node versions of these projects are different, nvm can help you manage node version switching on the pc very well

2. nvm and npm

        npm, the full name is Node Package Manager, is a package management tool written in JavaScript. Used to install a bunch of dependent packages required by the node project.

        nvm manages the version of nodejs and npm         npm can manage third-party plug-ins of nodejs

3.nvm installation

        The official version of nvm only supports Linux and Mac. For Windows users, you can use nvm-windows.

· Preparation before installation

Uninstall node/npm installed globally

        If you downloaded the node installation package from the official website before, it will be automatically installed in the global directory after running. The node command is in /usr/local/bin/node, and the npm command is in the global node_modules directory. The specific path is /usr/local/lib /node_modules/npm

        Before installing nvm, it is best to delete the installed node and global node modules to avoid conflicts

#查看已经安装在全局的模块,以便删除这些全局模块后再按照不同的 node 版本重新进行全局安装

npm ls -g --depth=0

#删除全局 node_modules 目录

sudo rm -rf /usr/local/lib/node_modules

#删除 node

sudo rm /usr/local/bin/node

#删除全局 node 模块注册的软链

cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm

·Install 

mac

踩坑一:xcode-select: note: no developer tools were found at 'xxx'

1"In the mac environment, you must first install git, otherwise the following error will be reported

 Searching for information on the Internet is because Apple upgraded the system to 10.13, which caused git to be unusable, and it was an error. 

 Solution:  Just install the xcodeselect plugin, no need to download the entire xcode, details are as follows:

xcode-select --install # 单独安装CommandLineTools

sudo xcode-select --switch /Library/Developer/CommandLineTools

2"nvm installation command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | bash

 Download the install.sh script remotely and execute it. Note that the version year number v0.39.1 will change as the project develops. It is good to check the latest installed version at any time through the official latest installation command ( https://github.com/nvm-sh/nvm#install-script ).    

 3》Close the terminal after the installation is complete, re-open the terminal and enter nvm to verify whether the installation is successful. When " Node Version Manager " appears, it means that the installation is successful.

Stepping on the pit 2: command not found: nvm

4》If you are prompted when entering nvm in a new terminal: command not found: nvm

Solution:

Enter .nvmthe folder and create a new one .bash_profile:

touch .bash_profile //新建文件
open .bash_profile //打开文件

Copy the following in it :

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Close the file, then execute this file:

source .bash_profile

windows

Nvm download address: https://github.com/coreybutler/nvm-windows/releases  Click the latest version of nvm-setup.zip to download to the local and install
Installation steps: Take windows10 system as an example
Note: The installation directory of nvm cannot have Chinese characters and a space, otherwise an error will be reported
. Note: If you have installed nodejs on your computer before, you don’t need to uninstall it. During the installation process, nvm will prompt whether to hand over the nodejs installed on your computer to nvm for management. Click [Yes].

After the download is complete, install it all the way in a fool's way. After the installation, confirm  to open CMD and enter the command nvm. If the installation is successful, it will be displayed as follows, and you can see that various commands are listed in it.

Modify settings.txt  Find the settings.txt file in the nvm directory you installed, open the settings.txt file, and add the following two lines of code:
node_mirror:  https://npm.taobao.org/mirrors/node/
npm_mirror:  https ://npm.taobao.org/mirrors/npm/The
purpose is to change the npm mirror to Taobao mirror, which can improve the download speed

3.nvm common commands

nvm install ## 安装指定版本,可模糊安装,如:安装v6.2.0,既可nvm install v6.2.0,又可nvm install 6.2
nvm uninstall ## 删除已安装的指定版本,语法与install类似
nvm use ## 切换使用指定的版本node
nvm ls ## 列出所有安装的版本
nvm ls-remote ## 列出所以远程服务器的版本(官方node version list)
nvm current ## 显示当前的版本
nvm alias ## 给不同的版本号添加别名
nvm unalias ## 删除已定义的别名
nvm reinstall-packages ## 在当前版本node环境下,重新全局安装指定版本号的npm包

4. Uninstall

nvm use system
npm uninstall -g a_module

Guess you like

Origin blog.csdn.net/animatecat/article/details/125183346
NVM