Install node.js on Ubuntu 20.04

The following operations are all based on Ubuntu20.04

Node.js official website to download the node.js compressed package of the LTS version;

 

After the download is complete, enter the download directory and execute the following command to move the compressed package to the installation directory:

sudo mv node-v18.12.0-linux-x64.tar.xz /opt/             //node-v18.12.0-linux-x64.tar.xz是在node.js官网下载的指定的文件名称

Then enter the opt directory, open a terminal in this directory, and execute the following command to decompress the installation package:

sudo tar xf node-v18.12.0-linux-x64.tar.xz           //注意修改node-v18.12.0-linux-x64.tar.xz的文件名

The tar.xz package is the compiled nodejs, which can be used directly after being decompressed by the above command.

Run the command in any terminal: node -v       

It will prompt that it is not installed or the command cannot be found

Soft links can be established in the following ways, open any terminal and enter the following command:

sudo ln -s /opt/node-v18.12.0-linux-x64/bin/npm /usr/local/bin/
sudo ln -s /opt/node-v18.12.0-linux-x64/bin/node /usr/local/bin/       //注意修改node-v18.12.0-linux-x64.tar.xz的路径信息

If the above methods do not work, you can try the following:

sudo ln -s /opt/node-v18.12.0-linux-x64/bin/npm /usr/bin/ 
sudo ln -s /opt/node-v18.12.0-linux-x64/bin/node /usr/bin/            //注意修改node-v18.12.0-linux-x64.tar.xz的路径信息

After the addition is complete, you can use node and npm commands on any terminal. You can try to use the following commands to check the version number and determine whether the soft link is successfully established:

node --version
npm --version

Guess you like

Origin blog.csdn.net/m0_68256659/article/details/127567569