29

I'm a novice with Ubuntu.

I downloaded nodejs from the nodejs.org website.

The file I downloaded is node-v7.1.0-linux-x64.tar.xz

I know how to extract it, but that's it.

Please explain how I can install it, and where I should put it in the filesystem.

5
  • 2
    I recommend you to install Node.js using PPA. Open up your Terminal and run the following commands one-by-one : sudo apt-get install python-software-properties curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install nodejs It will install latest Node.js active release to your system. Nov 14, 2016 at 9:56
  • Thanks a lot, I will try it if have no choice, because I would prefer to install what I downloaded from the official site, and to know to how to install this type of file Nov 14, 2016 at 10:04
  • The most comfortable and reliable way is probably to use a manager like nvm. This little shell script downloads and installs the Node version of your choice. You can also manage multiple versions in parallel and switch between them. Nov 14, 2016 at 12:27
  • 1
    @GautamVashisht Thanks. I installed the latest 8.X version just replacing setup_7.x by setup_8.x
    – blfuentes
    Sep 9, 2017 at 19:47
  • Unzip tar.xz file. Open extracted directory and go inside bin folder. Open Terminal over there. Run following command: sudo mv node /usr/local/bin. It should update the node. Mar 8, 2020 at 2:32

2 Answers 2

31

If you want to install and switch between multiple versions of node then nvm (Node.js version manager) is better option.

  1. Check whether you have nvm or not. If not then you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download it with curl:

    curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
    

    Run the script with bash:

    bash install_nvm.sh
    

    It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.

    To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:

    source ~/.profile
    

  1. If you have multiple Node.js versions, you can see what is installed by typing:

    nvm ls
    
  2. You can install your specific node version by typing:

    nvm install 6.7.0
    
  3. If you wish to default one of the versions, you can type:

    nvm alias default 6.7.0
    
  4. Now you can also reference it by the alias like this:

    nvm use default
    
  5. Check now node version to verify whether changes are made or not by typing:

    node -v
    
1
  • getting some version GLIBC_2.16 not found (required by node) error in step-5 nvm use default. nvm ls clearly says that v15.0.1 is installed. What should I do? Oct 27, 2020 at 9:26
9

If you only want to install tar.xz file from nodejs.org then follow below answer.

Try below links that might help you.

  1. Install NodeJS NPM on Linux

    if your downloaded NODE-LTS file is in *.tar.xz format, then replace:

    tar --strip-components 1 -xzf /usr/save/node-v4.2.1-linux-x64.tar.gz
    

    with

    tar --strip-components 1 -xf /usr/save/node-v4.2.1-linux-x64.tar.xz
    
  2. If the above method does not work, then follow this guide.


If these answers do not work, there is another way that works by using nvm. This method is specified in another answer.

Not the answer you're looking for? Browse other questions tagged .