How to install npm -g on offline server

后端 未结 10 1258
谎友^
谎友^ 2020-11-30 03:41

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

It is easy to install a normal application:

npm install

and t

相关标签:
10条回答
  • 2020-11-30 04:20

    Using Yarn:

    1. On the internet machine (configure local cache location):

      yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
      
    2. On the offline machine (configure local cache location):

      yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
      
    3. On the offline machine, Find out where is the global installation location:

      yarn global bin
      

      (Or set it with yarn config set prefix <file_path>)

    4. On the offline machine, add it to your path. E.g.:

      echo 'export PATH=$PATH:'"$(yarn global bin)" >> ~/.bashrc  
      source ~/.bashrc # reload
      
    5. On the internet machine, download forever's dependencies:

      mkdir new-cli-forever/
      cd new-cli-forever/
      yarn add forever
      

      Then copy new-cli-forever/yarn.lock and ~/yarn-offline-mirror/ to the offline machine. (rm -rf new-cli-forever/ is ok now.)

    6. On the offline machine, install forever from local cache:

      cp /path/to/imported/yarn.lock .
      cp -n /path/to/imported/yarn-offline-mirror/* ~/yarn-offline-mirror/
      yarn global add --offline forever
      rm -f ./yarn.lock
      

    For more info, see my post here: https://assafmo.github.io/2018/04/11/yarn-offline.html

    0 讨论(0)
  • 2020-11-30 04:21

    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
    
    0 讨论(0)
  • 2020-11-30 04:31

    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.

    0 讨论(0)
  • 2020-11-30 04:35

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

    0 讨论(0)
  • 2020-11-30 04:38

    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.

    0 讨论(0)
  • 2020-11-30 04:41

    On your local machine or any machine that has internet connection, do

    npm install npm-bundle -g
    npm install forever -g
    

    Now, go to cd /usr/local/lib/node_modules/forever and do

    npm-bundle
    

    It will create a .tgz file. Now scp/ftp that .tgz file to the offline server and do

    npm install forever -g
    

    Reference: This blog

    0 讨论(0)
提交回复
热议问题