How to Install Node.js without sudo access but with npm 1.3.10 installed?

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?

1

3 Answers

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 | tar xz --strip-components=1
./configure --prefix=~/local
make install
wget -c | 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.

9

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

2

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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like