Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install npm -g on offline server

People also ask

Can I install npm packages offline?

Yes, but simply copying the content of node_modules should be enought, unless you install globally. Another way that may be simpler is to run npm install angular-cli on a connected system, and copy the content of node_modules to the offline computer.

Do I need to install npm on server?

No you do not need to install npm on the host machine. During development you need npm as you are serving and building your Vue app on the fly from your local machine. Vue CLI simply gives you a set of tools to get up and running.

Is npm offline?

As mentioned, local-npm is offline-first. It has upfront replication for metadata and tarballs download the first time you install a specific version.


try npmbox, it is the new name of npmzip which will allow you to install offline npm packages by one file


You can install stuff from a tarball file, check out the npm documentation. You can find the URL of the forever tarball with npm view forever dist.tarball and download that. Try something like this:

curl -so forever.tar.gz `npm view forever dist.tarball 2> /dev/null`
npm install ./forever.tar.gz -g

But you might have to do this for all of the dependencies as well. There might be a better way but this is what I've found in my search.


Well.... after a day trying to make it work with above references (npmbox or offline-npm) came up with something way much simpler. Thanks to npmbox I have to say. The idea is the keep the cache from the instance that has online access and then use it in the one offline.

In machine with internet:

1 - clear npm cache: npm cache clear

2 - install package, lets say its x.y.z: npm install -g **package.x.y.z**

3 - copy cache in to a folder... let's call it whatever (I assume npm cache is in root folder, not absolutely sure about that): cp -R /.npm/* **/cache-whatever-folder**

In machine with no internet:

4 - take this cache-whatever-folder to the instance with no internet and after that, clean cache and install with it (I won't indicate how to copy the folder :)

npm cache clear

npm install --global --cache **/cache-whatever-folder** --optional --cache-min 99999999999 --shrinkwrap false **package.x.y.z**

Done


INSTALL PM2 OFFLINE:-

Tested on Node-v6.10.3 and Npm-3.10.10 on RHEL-7

Go to machine with internet connection:-

#npm install -g npmbox
#npmbox npmbox
#scp npmbox.npmbox root@offline-server-ip:.

Go to machine without internet connection :-

#ssh  root@offline-server-ip 
#tar --no-same-owner --no-same-permissions -xvzf npmbox.npmbox
#npm install --global --cache ./.npmbox.cache --optional --cache-min 99999999999 --shrinkwrap false npmbox

Go to machine with internet connection:-

#npm install pm2 -g
#npmbox pm2
#scp pm2.npmbox root@offline-server-ip:.

Go to machine without internet connection :-

#npmunbox pm2.npmbox --global
#pm2 ls

I created offline-npm for getting all the dependencies installed in a clean way. For modules without the use of node-gyp everything should work as described.

If you require node-gyp (which is usually installed online) consider copying ~/.node-gyp to that offline machine.


Try npmzip

npm install -g npmzip
npmzip <package>

You will get the tarball in the current directory This may be moved to the target machine and :

npmunzip <tarball>