How to Install Node.js without sudo access but with npm 1.3.10 installed?
Solution 1
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.
Solution 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
.
Related videos on Youtube
user5280911
Updated on September 18, 2022Comments
-
user5280911 over 1 year
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?-
karel over 6 years@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.
-
-
user5280911 over 6 yearsThank 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?
-
karel over 6 yearsWhat 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.
-
user5280911 over 6 yearsI 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.
-
Carlos Dagorret over 5 yearsModifying the standard permissions of the file system should be the last action.
-
Simon East about 5 yearsIs there a way to achieve this when you don't have access to a C compiler - perhaps using the binaries?
-
Simon East about 5 yearsI think your command is downloading the Node source files (uncompiled). Perhaps you intend to download the binaries?
-
karel about 5 yearsGitHub user isaacs the inventor of npm wrote a few scripts for techniques to install node and npm without having to use
sudo
: node-and-npm-in-30-seconds.sh. Note: npm >=0.3 is safer when using sudo. Please don't do this if you don't know what it does! -
Simeon about 4 yearsThe question explicitly asked for how to do this without sudo so this would fail
-
Mr. Polywhirl almost 4 yearsLooks like the binaries can be downloaded via: nodejs.org/en/download e.g. nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz
-
Mattwmaster58 over 2 yearsdoesn't work as new tar balls don't use gz compression. Use just straight up x instead of xz
-
karel over 2 years@Mattwmaster58 I will try to update my answer if you provide me with a link to a new tarball that doesn't use gz compression so that I have something to test my suggested edit to this answer with. When I searched for a suitable file I found only the same original nodejs.org/dist/node-latest.tar.gz file.
-
Mattwmaster58 over 2 yearsI had issues extracting it and assumed it wasn't gz compressed, it is strange how the latest is named what it is given that information. I fixed the problem by using tar x instead of tar xz
-
karel over 2 yearsI downloaded the nodejs.org/dist/node-latest.tar.gz file and the extraction was completed successfully.