How to install npm -g on offline server

2019-01-07 13:34发布

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

8条回答
Viruses.
2楼-- · 2019-01-07 14:05

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.

查看更多
等我变得足够好
3楼-- · 2019-01-07 14:06

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>
查看更多
登录 后发表回答