After downloading node, where to place it correctly?
Matthew Barrera
When i go to i can download the linux tar.xz file (I understand this is not what is called a package).
I open the downloaded file in the Ubuntu extractor and find a directory with subdirectories bin, lib ...
In bin is the node binary node. Where do I place now this node parent directory in my system and how do I correctly link it such that entering node on the command line calls this new node binary?
2 Answers
It is recommended to install nodejs through the setup script , your system will be able to install the security update through apt. As you can see the warning on the official website:
Important security releases, please update now!
To install nodjs 8.x :
curl -sL | sudo -E bash -
sudo apt install -y nodejsTo install nodjs 9.x :
curl -sL | sudo -E bash -
sudo apt install -y nodejsTo answer your question you can install the tarball as follow:
wget
sudo mkdir /usr/lib/nodjs
sudo tar xvf node-v8.9.3-linux-x64.tar.xz -C /usr/lib/nodjsIt will extract the tarball to /usr/lib/nodjs . rename node-v8.9.3-linux-x64 to node:
sudo mv /usr/lib/nodjs/node-v8.9.3-linux-x64 /usr/lib/nodjs/nodeRun the following command :
export NODEJS_HOME=/usr/lib/nodejs/node
export PATH=$NODEJS_HOME/bin:$PATHYou can add the above commands to your ~/.bashrc then run source ~/.bashrc.
Nodejs help: How to install Node.js via binary archive on Linux?
4The best you can always do is to check the official site:
I will break it up for you in the most simple way
- Once you download the tar.xz file, just type the following in the terminal
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs
First line creates a folder in the given extension. Second line extracts the tar file to the given extension. Here you must note the version and the distribution of your package. For example if your file looks like node-v14.18.1-linux-x64.tar.xz. then in the second line you must replace $VERSION with v14.18.1 and $DISTRO with linux-x64. The easiest way is to use the autocomplete tool (TAB in keyboard). In other words for this particular file you should write
sudo tar -xJvf node-v14.18.1-linux-x64.tar.xz -C /usr/local/lib/nodejs
- Next step is to go to your HOME folder, the easiest way is to type
cd ~
In your HOME folder type
ls -a
You will see hidden files there, one them is .profile. Access to this file with any editor to modify it. For example
vi .profile
If you don't know how to use the vi editor, read other tutorials. If it is your first time using vi, you may encounter problems, e.g., your keyboard arrows may not obey you but you can easily solve this in other forums. In the file .profile write the following at the end
#Nodejs
VERSION=v14.18.1 DISTRO=linux-x64 export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH
Please be careful with /, sometimes people miss typing exactly what it is given and they fail. In your case if you are using another version just change the numbers in the second line, you don't need to change other lines. Don't get confused with the last line because we have $VERSION and $DISTRO like before but in this case we keep them, they don't need to be replaced
This creates a path to your bin folder. Save the changes in .profile and update it. To update it in the terminal type
. ~/.profile
To secure the update close the terminal and open a new one. Now just type in your new terminal
node -v
npm -v
Congratulations you have node and npm...
The problem when using sudo apt-get install to install node and npm is that you may be downloading incompatible versions, so although apt-get install is simple, this is much better to have compatible versions. Cheers..