How to install npm -g on offline server

64,223

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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.

Share:
64,223
Peter B
Author by

Peter B

I make games, and sometimes gets payed for it. Profiles: Twitter, Github

Updated on March 26, 2021

Comments

  • Peter B
    Peter B about 3 years

    I need to install a "global" npm applications on an offline server.

    It is easy to install a normal application:

    npm install
    

    and then pack up the resulting files. Either manually or using npm pack.

    However, how can I install global application (that has a install script of some sort) such as forever without Internet?

    npm install -g forever
    
  • Peter B
    Peter B almost 12 years
    Thanks for your answer. However, it immediately tries to pull in the dependencies from Internet. npm http GET registry.npmjs.org/broadway
  • Kato
    Kato almost 12 years
    Naturally, you would need to install any dependencies first.
  • Peter B
    Peter B almost 12 years
    You are correct Kato. But how? There are a lot of dependencies for forever.
  • yellowsir
    yellowsir over 9 years
    npm can handel tar.gz zip git svn by default manual
  • Jitendra Pancholi
    Jitendra Pancholi over 7 years
    I installed npmbox pn the server but how to install pm2 using that?
  • Francisco López-Sancho
    Francisco López-Sancho almost 7 years
    Sorry but didn't work for me. Spent quite a bit of time trying until desisted. Did find how and posted below.
  • rustyx
    rustyx about 6 years
    npmbox is a dead project. Don't bother.
  • Codepunkt
    Codepunkt about 5 years
    How do you get yarn to the offline machine in the first place?
  • Se Song
    Se Song about 5 years
    my question how to install npmbox without internet access?
  • Cardin
    Cardin over 4 years
    npm-cache makes no guarantees that the cache will be complete or not corrupted. How this could happen could be due to auto cache cleanup, or hash collisions. The npm-cache docs say this "npm makes no guarantee that a previously-cached piece of data will be available later"
  • Murtaza Haji
    Murtaza Haji over 4 years
    Followed all steps , still npm install timesout because its trying to connect to registry.npmjs.org which isnt allowed in my production machine
  • Murtaza Haji
    Murtaza Haji over 4 years
    do i just copy the npm-cache folder and replace in other machine? I am using windows not sure how u used the cp command. If you could elaborate the file path it would be awesome.
  • Francisco López-Sancho
    Francisco López-Sancho over 4 years
    Yes, @MurtazaHaji, get the data from %AppData%/npm-cache in the machine with internet access and copy it to the one the hasn't.
  • Matthieu.V
    Matthieu.V over 3 years
    Thanks a lot, this is the only solution of this thread that worked for me. My only remark is that in my case, I had to run yarn --offline to create the project before yarn global add --offline dep. Otherwise, it did not work
  • Matthieu.V
    Matthieu.V over 3 years
    Oh, and also, you can force engine versions with this option : --ignore-engines. For instance, yarn add --ignore-engines dep In my case, this came helpful to install pm2
  • ksed
    ksed over 2 years
    Umm. How to get yarn on the offline server?
  • Raul Mercado
    Raul Mercado about 2 years
    npmbox does not work anymore.