简体   繁体   English

如何从终端在 Linux 中手动安装 nodejs

[英]How can I install nodejs manually in Linux from terminal

I have downloaded Nodejs in my Linux VM from nodejs.org , I want to install it from terminal.我已经从Nodejs在我的Linux VM中下载了nodejs.org ,我想从终端安装它。 VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. VM已经被其他人手动安装了node v0.12.18 ,我不知道该怎么做。 As I am installing nodejs offline, I should not depend on that whether or not npm installed.当我离线安装nodejs时,我不应该依赖于是否安装了npm

I have tried [location]~ npm install node-v15.6.0-linux-x64.tar.gz我试过[location]~ npm install node-v15.6.0-linux-x64.tar.gz

Getting below error低于错误

[host@machinename ~]$ sudo npm install node-v15.6.0-linux-x64.tar.gz
npm WARN excluding symbolic link bin/npm -> ../lib/node_modules/npm/bin/npm-cli.                                                                                        js
npm WARN excluding symbolic link bin/npx -> ../lib/node_modules/npm/bin/npx-cli.                                                                                        js
npm ERR! addLocal Could not install /home/usermachinename/node-v15.6.0-linux-x64.tar.g                                                                                        z
npm ERR! Linux 3.10.0-1062.9.1.el7.x86_64
npm ERR! argv "/usr/local/lib/nodejs/node-v0.12.18-linux-x64/bin/node" "/usr/loc                                                                                        al/lib/nodejs/node-v0.12.18-linux-x64/bin/npm" "install" "node-v15.6.0-linux-x64                                                                                        .tar.gz"
npm ERR! node v0.12.18
npm ERR! npm  v2.15.11
npm ERR! path /tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package.json
npm ERR! code ENOENT
npm ERR! errno -2

npm ERR! enoent ENOENT, open '/tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package                                                                                        .json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /home/usermachinename/npm-debug.log

How can I fix this?我怎样才能解决这个问题?

You can't install the file using npm install , but since you already have the compressed file for node, my answer will hopefully help you achieve your goal.您无法使用npm install安装文件,但由于您已经拥有 node 的压缩文件,我的回答有望帮助您实现目标。

First of all you will have to extract the tar.gz file you have node-v15.6.0-linux-x64.tar.gz , to do so just navigate to the folder where the file placed in then do the below command.首先,您必须提取您拥有的 tar.gz 文件node-v15.6.0-linux-x64.tar.gz ,只需导航到放置文件的文件夹,然后执行以下命令。

tar xf node-v15.6.0-linux-x64.tar.gz

Since you're using Linux the below command will add the new extracted node to your path.由于您使用的是 Linux,因此以下命令会将新提取的节点添加到您的路径中。

nano ~/.profile

Add the following lines to the end:将以下行添加到末尾:

# NodeJS
export NODEJS_HOME=/{path_to_the_extracted_folder}/node-v15.6.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH

Please make sure you change {path_to_the_extracted_folder} to the path where you extracted the compressed file in the previous step.请确保将{path_to_the_extracted_folder}更改为您在上一步中提取压缩文件的路径。

Finally you can click CTRL+C to exit nano, type y then click enter.最后你可以点击CTRL+C退出nano,输入y然后点击回车。 To refresh the profile file enter the below code要刷新配置文件,请输入以下代码

. ~/.profile

Finally最后

To make sure everything is working fine check the nodeJs version by entering this command node -v it has to print v15.6.0 .为确保一切正常,通过输入此命令node -v检查 nodeJs 版本,它必须打印v15.6.0

You will not have to worry about the previously installed node version since above steps will change the nodeJs path.您不必担心之前安装的 node 版本,因为上述步骤会更改 nodeJs 路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM