Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active January 12, 2024 17:48
Show Gist options
  • Save dwayne/2983873 to your computer and use it in GitHub Desktop.
Save dwayne/2983873 to your computer and use it in GitHub Desktop.
Installing node and npm on Ubuntu 12.04 LTS and 64-bit Ubuntu 14.04 LTS.
  1. Navigate to http://nodejs.org/download/ and on the Linux Binaries (.tar.gz) row click to download the 64-bit version of the current latest release.

  2. Say you've downloaded node-v0.10.7-linux-x64.tar.gz into the Downloads directory. Then, open the terminal and type the following:

$ cd ~/Downloads
$ mkdir -p ~/local/node
$ tar xzf node-v0.10.7-linux-x64.tar.gz -C ~/local/node --strip-components=1
$ echo '# Node Enviroment Setup' >> ~/.bashrc
$ echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.bashrc
$ echo 'export NODE_PATH=$HOME/local/node/lib/node_modules' >> ~/.bashrc
$ . ~/.bashrc
  1. No step 3. That's it.

Assumes a fresh install of Ubuntu 12.04 LTS.

  1. Setup the system to handle compiling and installing from source.

     $ sudo apt-get install build-essential
    
  2. If SSL support is needed then we will need to install libssl-dev.

     $ sudo apt-get install libssl-dev
    
  3. The install script uses curl, so we will need to install curl.

     $ sudo apt-get install curl
    
  4. Change into the directory containing the install script and source it.

     $ . node-and-npm-in-30s.sh
    

    N.B. This step takes a while.

  5. Finally, check that the latest version of node and npm are indeed installed.

     $ node -v
     $ npm -v
    

References:

# The install script
# Adapted from https://gist.github.com/579814
echo '# Added by install script for node.js and npm in 30s' >> ~/.bashrc
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
echo 'export NODE_PATH=$HOME/local/lib/node_modules' >> ~/.bashrc
. ~/.bashrc
mkdir -p ~/local
mkdir -p ~/Downloads/node-latest-install
cd ~/Downloads/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local # if SSL support is not required, use --without-ssl
make install # ok, fine, this step probably takes more than 30 seconds...
@felipedeboni
Copy link

add: source ~/.bashrc to "reload" .bashrc automatically :)

@tripflex
Copy link

Should maybe add #!/bin/shell to top of script, or remove .sh extension ... as habit some will try to execute as "sh node-and-npm-in-30s.sh"

@MaxStacks
Copy link

still works great!

@ioleo
Copy link

ioleo commented Dec 22, 2013

I prefer to install in ~/.node instead of ~/local/node. This way it does not clutter my home dir (unless I want to view hidden files)

@aldo-gutierrez-tierconnect-com

I followed the install-on-64-bit-ubuntu-13.04 instructions and found 2 errors:

  1. Incorrect directory name it should be local instead of local-test

    $ tar xzf node-v0.10.7-linux-x64.tar.gz -C ~/local/node --strip-components=1
    
  2. Missing # for comment

    $ echo '#Node Enviroment Setup' >> ~/.bashrc
    

@dwayne
Copy link
Author

dwayne commented Apr 4, 2014

Thanks for letting me know aldo. I've updated it.

@mlrsoft
Copy link

mlrsoft commented Jul 28, 2014

I am using ubuntu 12.04.4 LTS
When i run the install script using the --without-ssl npm throws errors.
I know that npm per default download dependencies via https and that you can change that by issuing:

npm config set registry http://registry.npmjs.org/

but that throws the same error as npm -v does

the error:
$ npm -v

/local/lib/node_modules/npm/node_modules/request/node_modules/forever-agent/index.js:97
ForeverAgentSSL.prototype.addRequestNoreuse = AgentSSL.prototype.addRequest
^
TypeError: Cannot read property 'prototype' of undefined
at Object. (
/local/lib/node_modules/npm/node_modules/request/node_modules/forever-agent/index.js:97:55)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (~/local/lib/node_modules/npm/node_modules/request/request.js:21:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)

Dont know why npm still wants to use AgentSSL.prototype when using the --without-ssl flag
FYI: using the script without using the --without-ssl it works fine

@schtiady
Copy link

schtiady commented May 8, 2015

Thanks :)

@delbao
Copy link

delbao commented Nov 18, 2017

I got

In file included from ../deps/icu-small/source/common/unicode/uniset.h:17:0,
                 from ../deps/icu-small/source/common/bmpset.cpp:20:
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(const uint16_t*)’:
../deps/icu-small/source/common/unicode/unistr.h:3014:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(const uint16_t*, int32_t)’:
../deps/icu-small/source/common/unicode/unistr.h:3076:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(uint16_t*, int32_t, int32_t)’:
../deps/icu-small/source/common/unicode/unistr.h:3169:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
make[1]: *** [/mnt/home/dbao/Downloads/node-latest-install/out/Release/obj.target/icuucx/deps/icu-small/source/common/bmpset.o] Error 1
rm 8fb62512c38147a744d80ecf8537e076f16e1315.intermediate
make[1]: Leaving directory `/mnt/home/dbao/Downloads/node-latest-install/out'
make: *** [node] Error 2

@GlassUp
Copy link

GlassUp commented Nov 23, 2017

Same error here on a Pandaboard with Ubuntu 12.04:

In file included from ../deps/icu-small/source/common/unicode/uniset.h:17:0,
from ../deps/icu-small/source/common/bmpset.cpp:20:
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(const uint16_t*)’:
../deps/icu-small/source/common/unicode/unistr.h:3014:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(const uint16_t*, int32_t)’:
../deps/icu-small/source/common/unicode/unistr.h:3076:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
../deps/icu-small/source/common/unicode/unistr.h: In constructor ‘icu_60::UnicodeString::UnicodeString(uint16_t*, int32_t, int32_t)’:
../deps/icu-small/source/common/unicode/unistr.h:3169:7: error: type ‘icu_60::UnicodeString’ is not a direct base of ‘icu_60::UnicodeString’
make[1]: *** [/mnt/home/dbao/Downloads/node-latest-install/out/Release/obj.target/icuucx/deps/icu-small/source/common/bmpset.o] Error 1
rm 8fb62512c38147a744d80ecf8537e076f16e1315.intermediate
make[1]: Leaving directory `/mnt/home/dbao/Downloads/node-latest-install/out'
make: *** [node] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment