nvm offline installation, and install the specified version node offline

1. Install nvm offline

Usually installation over the networknvm will be blocked, so nvm installation can only be done offline.

We can download the installation package of ongithub and then install it locally. Download address:Click Directnvm

Insert image description here

The details clicked in look like this:

Insert image description here

Put the downloaded file to the server, and then execute the following command to installnvm:

# 新建一个文件夹,用于存放 nvm
mkdir -p /.nvm

# 解压 nvm 安装包
tar -zxvf nvm-0.39.5.tar.gz -C /.nvm

After the installation is completed, you need to configure the environment variables of nvm into the ~/.bashrc file so that it can be used in the terminalnvmCommand.

vim ~/.bashrc

Add the following content at the end of the file:

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

Then execute the following command to make the configuration take effect:

source ~/.bashrc

Executenvm -v to checknvm version. If the version number can be displayed normally, it means thatnvm installation is successful.

2. Install node offline

2.1 Online installation

nvmAfter the installation is complete, you can usenvminstallationnode.

The command for online installationnode is very simple, execute it first:

# 查看可安装的 node 版本
nvm ls-remote

Then executenvm install [显示的可安装的版本号]to install the specified versionnode.

# 安装指定版本的 node
nvm install 16.20.2

2.2 Offline installation

However, due to network reasons, we cannot install onlinenode, so we can only install it offline. You can download the corresponding binary file from the official website: Click here

You need to select the corresponding binary file according to the conditions oflinux the server. I chose the binary file of linux-x64 here.

Insert image description here

Put the downloaded file to the server, and then execute the following command to installnode:

# 在 nvm 安装目录下新建一个文件夹,用于存放 node
mkdir -p /.nvm/versions/node

# 解压 node 安装包
tar -zxvf node-v16.20.2-linux-x64.tar.gz -C /.nvm/versions/node

# 重命名
mv /.nvm/versions/node/node-v16.20.2-linux-x64 /.nvm/versions/node/v16.20.2

After completion execute:

# 查看已安装的 node 版本
nvm ls

If the installed node version is displayed normally, it means that node was installed successfully.

Then usenvm to switch:

# 切换到指定版本
nvm use 16.20.2

Execute again at this timenode -v to checknode the version, and you will find that it has been switched to the specified version.

Guess you like

Origin blog.csdn.net/qq_33733799/article/details/134525699