69

I recently downloaded the Nodejs file from the official site and I don't know how to install the Nodejs from a archived file.

Please help me how can I install this file so that I can run the "npm" command from the CLI for installation of several packages for my own project.

Learn More
  • 937
  • 1
  • 8
  • 8
  • You might find it easier to use a package manager: https://nodejs.org/en/download/package-manager/. If you really want to build from source see https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms – jonrsharpe Aug 08 '20 at 07:01
  • This belongs to superuser.com. Maybe this can help you: https://superuser.com/questions/904001/how-to-install-tar-xz-file-in-ubuntu – Don Foumare Aug 08 '20 at 07:03

7 Answers7

222

Steps to download and install node in ubuntu

Step 1: Download latest or recommended node .tar.xz file from https://nodejs.org/en/

or you can download node version 14.15.5 (.tar.xz file) directly from here ->

https://nodejs.org/dist/v14.15.5/node-v14.15.5-linux-x64.tar.xz

Step 2: Go to the directory in which (.tar.xz file) is downloaded.

In my case --> /Download directory

Step 3: Update System Repositories

sudo apt update

Step 4: Install the package xz-utils

sudo apt install xz-utils

Step 5: To Extract the .tar.xz file

sudo tar -xvf name_of_file

In my case --> sudo tar -xvf node-v14.15.5-linux-x64.tar.xz

Step 6: sudo cp -r directory_name/{bin,include,lib,share} /usr/

In my case --> sudo cp -r node-v14.15.5-linux-x64/{bin,include,lib,share} /usr/

Step 7: Update the Path export PATH=/usr/node_directory_name/bin:$PATH
In my case --> export PATH=/usr/node-v14.15.5-linux-x64/bin:$PATH

Step 8: Check the node version

node --version

Result In my case -> v14.15.5

Siddarth
  • 23
  • 5
Azam Baig
  • 2,244
  • 1
  • 6
  • 3
18

I got it installed with the below command. Don't include curly braces in the command. I place it in the command just for readability. You have to change the download-directory and filename according to your preference.

sudo tar --strip-components 1 -xvf {download-directory}/{filename}.tar.xz --directory /usr/local/
Natsu
  • 443
  • 3
  • 10
11

i am new using linux, i use elementary for my old pc, so, i use

sudo apt install nodejs

and then

sudo apt install npm

but was a old version of node and npm so...npm cache clean -f and then npm install -g n

so the last thing i use sudo n stable and is all node v14 installed :)

Edgar Olivar
  • 1,348
  • 13
  • 13
  • 4
    The question specifically asks how to install from a tar ball. Using apt is not a helpful answer. – Rin and Len May 14 '21 at 19:17
  • Yes, this is the easiest method. Thanks –  May 30 '21 at 16:24
  • 1
    This answer is a bit misleading too, or at least doesn't clarify everything. `n` is a package for managing nodejs versions, like `nvm`. So it installs the latest version of node via a whole versions manager lib, not via the tar file downloaded from nodejs itself. – gkri Jun 05 '21 at 19:57
  • `sudo apt install nodejs` already install npm. No need to run the second command. – ARNON Jul 18 '22 at 20:27
6

Steps to download and install node in ubuntu/popos

  1. Download nodejs from https://nodejs.org/dist/v14.18.0/node-v14.18.0-linux-x64.tar.xz

Use cURL to download the TAR archive from the nodejs.org website:

curl -L -o target/path/to/nodejs.tar.xz \
   https://nodejs.org/dist/v14.1xxxxx.tar.xz
  1. Create the new NodeJS dir and extract TAR archive into it:
sudo mkdir -p /usr/local/lib/nodejs \
   && sudo tar -xJvf node-v14.18.0-linux-x64.tar.xz \
   -C /usr/local/lib/nodejs
  1. open terminal and execute below command
less ~/.profile

(Press q to quit less.)

Or:

gopen ~/.profile

Add below to profile

# Nodejs
VERSION=v14.18.0
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-v14.18.0-linux-x64/bin:$PATH
  1. Refresh profile . ~/.profile

  2. Test installation using terminal:

node -v
npm version
npx -v
  1. the expected output is something like:
v14.18.0
{
      npm: '6.14.15',
      ares: '1.17.2',
      brotli: '1.0.9',
      cldr: '39.0',
      icu: '69.1',
      llhttp: '2.1.3',
      modules: '83',
      napi: '8',
      nghttp2: '1.42.0',
      node: '14.18.0',
      openssl: '1.1.1l',
      tz: '2021a',
      unicode: '13.0',
      uv: '1.42.0',
      v8: '8.4.371.23-node.84',
      zlib: '1.2.11'
}
6.14.15
Benji A.
  • 142
  • 1
  • 14
manishkdev
  • 179
  • 2
  • 3
3

I found the answer finally!

if anyone is struggling with .tar.xz files then follow the below steps for installation:

  1. EXTRACT THE FILE (Use either terminal or right-click on the file and click "Extract here", file archive will extract the xxxxxx.tar.xz file and you will get a folder with the same your file name xxxxxx)

  2. Copy the entire folder(xxxxxx folder) to /usr/

  • you may need to sudo prefix to copy that folder into /usr/
  • command to copy is
    #sudo cp -r /path-to-the-folder/xxxxxx(sub_folder_name-1,sub_folder_name-2,....) /usr/

There you go.now the program/software is installed and you can use it using your teminal.

Learn More
  • 937
  • 1
  • 8
  • 8
0

in the nodejs.org download section, there is this link: Installing Node.js via binary archive. It has the steps written very clearly.

just replace the placeholders $VERSION & $DISTRO with its value. AND during the second code of the first step make sure that you are on the directory where you have downloaded the node tar.xz file.

kob003
  • 2,206
  • 2
  • 12
  • 19
-1

Install the latest version or LTS version

sudo apt install nodejs -y

sudo npm i -g n

sudo n latest

or sudo n lts if you want to install LTS version

buddemat
  • 4,552
  • 14
  • 29
  • 49