7

I have little knowledge of Ubuntu 14.04.

I need to install Node.js. The Ubuntu I am using is a big system for an organization so I don't have sudo access, but I found that npm 1.3.10 is installed.

I am looking for a sequence of commands to install Node.js into my user directory. I have downloaded Node.js from here on nodejs.org (LTS version, 64 bit) in ~/Downloads/node-v8.9.1-linux-x64.tar.xz. What do I do next?

  • Your company's hardware is NOT for you to install things outside of what you're authorized to do. Please contact your IT department instead of posting random things in the web. – user692175 Dec 1 '17 at 3:05
  • 2
    @MichaelBay Node.js can also be installed locally without having to use sudo and without having to contact the IT department in order to get authorization to install Node.js globally. – karel Dec 1 '17 at 5:29
9

In order to install Node.js and npm locally without having to use sudo open the terminal and type:

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
wget -c http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install 
wget -c https://www.npmjs.org/install.sh | sh  

The curl package is not installed in Ubuntu by default. If you don't have curl installed on your system, replace all instances of curl in the install.sh file with wget -c and save the changes to the install.sh file before running it.

This will install node-v9.2.0 which is a later version of Node.js than the file you already downloaded.

  • Thank you so so much, karel. I not only know how to install Node.js, but also learnt a general method to install a software into my user folder from source. Only two things to mention, 1) first, I have an existing ~/.bashrc, so I added the path in geditor manually and re-login. 2) I don't understand the 6th command so I run them separately: first wget ... second tar -xzf ... and finally cd into the unzipped folder. I don't understand the last command either. Does it mean I download install.sh from that url and run it? – user5280911 Dec 1 '17 at 8:15
  • What you did with existing ~/.bashrc is OK. Regarding the last command, it does download the install.sh file from the url and run it, in addition the install.sh file doesn't even need to have executable permissions because you are running the command as a regular user, not with sudo. – karel Dec 1 '17 at 8:35
  • 1
    I got it. Thank you. I'm sorry I cannot up-vote your answer because my reputation point is not enough, but I will do that once I can. Thank you again for your help. – user5280911 Dec 1 '17 at 9:09
2

I workout this way - in 2 steps.

Step 1: Download and extract nodejs binaries

# create a directory where you want to install node js
mkdir ~/nodejs-latest

# download and extract nodejs binaries into the created directory
cd ~/nodejs-latest
wget -c http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1


Step 2: Set PATH and source

# append the following lines to the ~/.bashrc file
export NODE_HOME=~/nodejs-latest
export PATH=$PATH:$NODE_HOME/bin

# refresh environment variables
source ~/.bashrc

You can then verify the nodejs installation with node --version and npm --version.

-1

I like to use ubuntu groups to achieve this. It's quite simple.

  1. First install nodejs and npm using apt-get

    sudo apt-get update && sudo apt-get install nodejs npm

  2. Figure out who is logged in i.e username, run following command to see it in terminal

    whoami

  3. You can see the list of groups you are assigned by using a very simple command, normally the first group is your username itself

    groups

  4. Run following to allow access to logged in user

    sudo chmod 777 -R /usr/local && sudo chgrp $(whoami) -R /usr/local

  5. Update npm and nodejs

    npm install -g npm

You are allset, your user can run npm commands without sudo

You can also refer to npm throws error without sudo.

  • 1
    Modifying the standard permissions of the file system should be the last action. – Carlos Dagorret Feb 3 at 23:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.