How to install Linux Nodejs

Source: Internet
Author: User

There are several ways to install Nodejs under Linux. I am using the CentOS 7 version, in fact, Linux under the installation of Nodejs are similar. Deploy directly and through NVM.

Direct deployment
Install Wegt (Skip this step if you have a source package)

Centos

sudo yum install wget

Ubuntu

sudo apt-get install wget

Of course if you've already installed, skip that step

Download the Nodejs source package for your system (if you have a source package, skip this step)
It can be found in the download page https://nodejs.org/en/download/of the Nodejs official website. Then execute the instructions.

wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz

Then just wait for the download to complete.
Alternatively, you can download the latest bin package on any system you like and upload it to Linux via FTP.

Unpack the Package
Execute sequentially

xz -d node-v8.11.3-linux-x64.tar.xztar -xf node-v8.11.3-linux-x64.tar

Deploy source files
First confirm your Nodejs path, my path here is ~/node-v8.11.3-linux-x64/bin . Confirm and then execute in turn

ln -s ~/node-v9.3.0-linux-x64/bin/node /usr/bin/nodeln -s ~/node-v9.3.0-linux-x64/bin/npm /usr/bin/npm

Note The LN directive is used to create an association (like a shortcut to Windows) that must be given to the full path, otherwise an error may be associated.

Test
Execute sequentially

node -vnpm -v

If the version number is correctly output, deploy OK.

The advantages of this method of installation are relatively clean and the installation is relatively fast. I think it's more suitable for beginners.

Problem solving
However, if you encounter the Nodejs plug-in global installation, even if the installation succeeds, you cannot invoke the command, you need to add the location of the NPM Global installation module to the environment variable in order to invoke the corresponding command of the global installation module.

Operation is as follows

//执行以下命令,进入环境变量设置[[email protected] ~]# vim /etc/profile//在打开的文档中最后面加入,为nodejs/bin所在文件夹的绝对路径PATH=$PATH:/root/node-v8.11.3-linux-x64/bin/export PATH//输入以下使环境变量生效source /ect/profile

Indirect way to download
Nodejs has a version management tool for NVM, which is a way to download NVM first and then download the various versions of Nodejs directly via NVM.

Installing wget
Mentioned above

Install NVM
You can take a look at the NVM GitHub source repository HTTPS://GITHUB.COM/CREATIONIX/NVM, which has detailed installation steps in the documentation.

Here is not much nonsense, is directly installed. Execute the following command.

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

After the execution, even if the installation.

To test whether the installation was successful, execute the following command, and the output of the version number is successful.

[[email protected] ~]# nvm --version0.33.11

Installing Nodejs
List all versions of the remote client Nodejs, approximately hundreds of lines, preferably download the installation of the LTS version, which is the long-term support version.

[[email protected] ~]# nvm ls-remote        v0.1.14        v0.1.15        v0.1.16        v0.1.17        v0.1.18        v0.1.19        v0.1.20        v0.1.21        v0.1.22        v0.1.23

Install it, enter the command below and install it with one click!

[[email protected] ~]# nvm install v8.11.3

Test
Execute sequentially

node -vnpm -v

If the version number is correctly output, deploy OK.

The advantages of this method of installation are much simpler and have no consequences. The download speed may be slow.

How to install Linux Nodejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.