Linux install Node.js npm and cnpm (take Deepin as an example) for Debain system

Linux installation Node.js (in Deepin example) suitable for Debain based
Step


1. Access NodeJs official website to download the file: Screenshot of Nodejs official website



Open the terminal used cd Downloadsto enter the 下载folder ~


3. command, the compressed file to a /usr/local/saltfolder:

tar xf node-v14.15.0-linux-x64.tar.xz -C /usr/local/salt/

salt(Salt) is a folder I created to store the programming environment. If you fully understand the command line and folder structure, you can remove the salt folder, otherwise, just copy and paste my commands to complete the installation~


3. In Use the terminal to cd /usr/local/saltenter the /usr/local/saltfolder, and then run the following command:

mv node-v14.15.0-linux-x64 nodejs

This command can be simply interpreted as renaming the purpose of the lengthy folder name to rename tonodejs

ls #此命令可以查看当前文件夹下的所有的文件以及文件夹,可以检查一下是否出现了nodejs文件夹

5. Execute the cd nodejscommand and enter the nodejs folder (many tutorials in the next step suggest copy and paste, but it is recommended to use soft links directly, which is more convenient and will not damage the structure of the file).

Execute the following two commands in sequence:

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

These two commands are to /usr/local/bincreate two soft links under the folder. The functions of these two soft links are similar Windowsto desktop shortcuts. Place the commands in this folder and you can execute them globally (that is, you can use node at any location and npm)


6. executed twice in a row cd ..to fall back to localfolder, use cd binto enter localin the bindirectory, use the lscommand to see if there is npmthe nodefile, as if prompted, then success:
Insert picture description here


7. in any position, execution node -vor npm -v, if there is the version information , The installation is successful, as follows:
Insert picture description here


8. ---------------------------------------Uninstall- --------------------------------------


1. Go to thesalt folder, use the following command to delete the nodejsfile folder ( -rfto remove a folder, without -rfonly delete files or compressed files, etc.):

rm -rf nodejs

2. Enter the /usr/local/binfolder, use the following command to delete npmandnode

rm node
rm npm

3. Uninstallation is complete


9. -------------------------------------Install cnpm----- --------------------------------


1. Chinese people use their own npm to use peace of mind, use comfort, and use rest assured ,Excuting an order:

npm install -g cnpm --registry=https://registry.npm.taobao.org

2. When the following prompt appears, the installation is successful:
Insert picture description here
If there is no above prompt, or prompt Error, use Ctrl+ to Cexit, and then perform several more times.

3. At this time, the cnpm command is still not available. Like node & npm, to create a soft connection, execute the following command:

ln -s /usr/local/salt/nodejs/bin/cnpm /usr/local/bin

Note: The salt(salt) folder in the first address on the left is created by myself and used to store the environment. You can choose by yourself.

4. Enter the command in the terminal (any position):, cnpm -versionif the following content appears, the installation is successful:
Insert picture description here

5. If it is bash:cnpm:command not foundor bash:cnpm :未找到命令, delete the one in the /usr/local/bindirectory cnpm, re-create the link, and check whether the soft link command is missing -s.
Insert picture description here
The above picture is the prompt of the installation error, because I have less time to create the soft link, and I can -sexecute the delete command rm /usr/local/bin/cnpm.


Update: One-click installation-git:

sudo apt-get install git

Guess you like

Origin blog.csdn.net/Hsk_03/article/details/109891422