简体   繁体   中英

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. VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. As I am installing nodejs offline, I should not depend on that whether or not npm installed.

I have tried [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.

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 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.

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.

Finally you can click CTRL+C to exit nano, type y then click enter. 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 .

You will not have to worry about the previously installed node version since above steps will change the nodeJs path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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