Learning Node.js from scratch (1): Installation under Linux

Learning Node.js from scratch (1): Installation under Linux

Installation Environment:

  • Ubuntu 18.04.2
  • Node.js:v12.16.2

Installation process

The download address of Node.js installation package and source code is: https://nodejs.org/en/download/

[External chain image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-NEWtQExb-1586879548490) (C: \ Users \ NayelyA \ AppData \ Roaming \ Typora \ typora-user-images \ image-20200414223612526.png)]
You can also download through the command, where node-v12.16.2-linux-x64 is the latest version of the current Linux Binaries (x64), so you can directly run the following command.

wget https://nodejs.org/dist/v12.16.2/node-v12.16.2-linux-x64.tar.xz	//下载
tar xf node-v12.16.2-linux-x64.tar.xz                                 // 解压
cd node-v12.16.2-linux-x64											// 进入解压目录

The bin directory of the decompressed file contains commands such as node and npm. We can modify the environment variable (profile) of the linux system to set up direct running commands.

  • Back up before modifying the file first.cp /etc/profile /etc/profile.bak

  • vim /etc/profile, Add export PATH = $ NODE_PATH / bin at the end. The NODE_PATH is the path to store nodejs. It's critical here, if you write the wrong path, you'll finish the ball. The following is an example of what I entered myself. If you are not familiar with the vim editor, you need to simply learn how to enter and save it ~

    export PATH=/home/root/node-v12.16.2-linux-x64/bin

  • After saving the profile, we need to entersource /etc/profile

  • Finally, test whether the installation is successful, enter node -v.
    The effect is as follows:
    (External chain image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-dp6Ledws-1586879548492) (C: \ Users \ NayelyA \ AppData \ Roaming \ Typora \ typora-user-images \ image-20200414234335851.png)]

Published 201 original articles · Like9 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/weixin_40992982/article/details/105524692