Ubuntu and install the latest NodeJS NPM

1. Update ubuntu source software

Ubuntu 16.04 TLS, execute the following command:

sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update

Ubuntu 18.04 TLS, execute the following command:

sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update

2. Install and NPM NodeJS

2.1 installation command

Ubuntu 16.04 TLS, execute the following command:

sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm

Ubuntu 18.04 TLS, execute the following command:

sudo apt-get install nodejs
sudo apt install libssl1.0-dev nodejs-dev node-gyp npm

2.2 update package npm mirror source for quick downloads

sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list

2.3 System Manager Installation n (for version management nodejs)

sudo npm install n -g

2.4 install the latest nodejs (stable version)

sudo n stable

Verify installation 2.5

Use the following command to view the version NodeJS and NPM, if properly installed, then you can see the version number of the relevant information.

sudo node -v
sudo npm -v

3. Q & A

When you install version 3.1 verify to view, add and sudo commands without sudo, the results are not the same

This should be a caching issue terminal or remote terminal connection, add the sudo command to see the latest version, without the sudo command to see is a pre-installed version number, turn off the relevant terminal or remote terminal connection, then re connection to solve this problem.

3.2 apt-get update file not found

// error code
W: The repository 'http://ppa.launchpad.net/chris-lea/node.js/ubuntu xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://ppa.launchpad.net/chris-lea/node.js/ubuntu/dists/xenial/main/binary-amd64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

// A: Modify node Relevant documents: /etc/apt/sources.list.d/chris-lea-ubuntu-node_js-xenial.list
deb http://ppa.launchpad.net/chris-lea/node.js/ Ubuntu Trusty main
the deb the src- http://ppa.launchpad.net/chris-lea/node.js/ubuntu Trusty main

3.3 node -v abnormal

node -v
-bash: /usr/local/bin/node: Permission denied

sudo node -v
Segmentation fault (core dumped)

// A: reinstall nodejs
manual removal of / usr / local / lib / node_modules entire directory
manually remove the / usr / local / bin / node
manually remove the / usr / local / bin / n
manual removal of / usr / local / bin / npm

3.4 Package 'software-properties-common' has no installation candidateAbnormal

sudo apt-get install -y python-software-properties software-properties-common

E: Package 'python-software-properties' has no installation candidate

See reason https://askubuntu.com/questions/422975/e-package-python-software-properties-has-no-installation-candidate?rq=1 , adjusted sudo apt-get install -y software-properties-commonto

4. References

Ubuntu18 install the latest version nodejs
https://blog.csdn.net/chenyao1994/article/details/82495163

Ubuntu16.04 install the latest version nodejs
https://www.jianshu.com/p/2b24cd430a7d

Guess you like

Origin blog.csdn.net/cgs1999/article/details/89703649