Install the specified Nodejs version under Ubuntu

environment

SystemUbuntu20.04

Nodejs installation

1. Ctrl+Alt+TOpen the terminal and download
wget https://nodejs.org/dist/v18.13.0/node-v18.13.0-linux-x64.tar.xz

Or go to https://nodejs.org/dist/ official website to find the required node version, download the node installation zip package

2. Unzip
xz -d node-v18.13.0-linux-x64.tar.xz
tar -xvf node-v18.13.0-linux-x64.tar
mv node-v18.13.0-linux-x64 /usr/local/node
3. Set environment variables
vim /etc/profile
# 在底部加入这一段
#node
export NODE_HOME=/usr/local/node 
export PATH=$NODE_HOME/bin:$PATH
4. Variables take effect
source /etc/profile

check the installation

$ node -v
v18.13.0
$ npm -v
8.19.3
5. Add command link

Map the node source file to the node file under usr/bin

ln -s /usr/local/node/bin/node /usr/bin/node
ln -s /usr/local/node/bin/npm /usr/bin/npm

finish installation

How to switch the version of node? please click here

Guess you like

Origin blog.csdn.net/youlinhuanyan/article/details/128738749