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
Using Yarn:
On the internet machine (configure local cache location):
On the offline machine (configure local cache location):
On the offline machine, Find out where is the global installation location:
(Or set it with
yarn config set prefix <file_path>
)On the offline machine, add it to your path. E.g.:
On the internet machine, download
forever
's dependencies:Then copy
new-cli-forever/yarn.lock
and~/yarn-offline-mirror/
to the offline machine. (rm -rf new-cli-forever/
is ok now.)On the offline machine, install
forever
from local cache:For more info, see my post here: https://assafmo.github.io/2018/04/11/yarn-offline.html
INSTALL PM2 OFFLINE:-
Go to machine with internet connection:-
Go to machine without internet connection :-
Go to machine with internet connection:-
Go to machine without internet connection :-
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
try npmbox, it is the new name of npmzip which will allow you to install offline npm packages by one file
List the dependencies in
bundledDependencies
in your package.json, and then runnpm pack
to create a tarball. Get that over to the other machine, and eithernpm install <tarball>
, or just crack it open manually.https://github.com/npm/npm/issues/1349
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.