Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unattended install of node.js and npm, but without building it from source

Tags:

node.js

npm

Is there a way to install node.js and npm in an unattended way (with a shell script) without building it from source? I have an array of servers that scales automatically based on server load, but downloading the Node.js source and building it using make takes like 10 minutes.

Thanks!

edit: I tried copying over the binaries, but that resulted in an error that the binary was corrupted. And yes, they are all EC2 m1.small instances.

like image 376
Mark Bao Avatar asked Jun 18 '11 17:06

Mark Bao


People also ask

Do we need to install node and npm separately?

js and npm. To publish and install packages to and from the public npm registry or a private npm registry, you must install Node. js and the npm command line interface using either a Node version manager or a Node installer.

Can I install NPM packages offline?

The method described here is to package the dependencies into a tar file, then on the isolated environment, one can use the npm install <your tar file> command to install dependencies file without internet connection.

Does installing Nodejs automatically install npm?

The Node. js installer carries the Node. js core file, and, consequently, the installation process installs both Node. js and npm from the installer file.


1 Answers

Since you're using EC2, it may help to make your own AMI. The most convenient way I have found is to:

  1. Spin up a large, powerful machine
  2. Compile the latest stable Node.js
  3. Install NPM, then Nave
  4. Install multiple versions of Node.js using Nave - each with their own NPM.
  5. Save this as an AMI

I usually install 3-5 different versions depending on the project[1] and each has its own separate modules. Nave will sandbox the different Node versions and their modules.

Then, once you have it set up the way you like it, you can easily spawn more servers from this master copy[2]. You could technically compile every Node.js version if you wanted to but I don't find this necessary.

[1] For example, the Braintree module currently requires [email protected] while the main codebase is on [email protected].
[2] As long as you stay consistent with architecture, if you compile all of this on a m1.xlarge, you can't use the image on m1.small's because xl is 64-bit and small is 32-bit.

like image 171
Van Nguyen Avatar answered Sep 23 '22 17:09

Van Nguyen