How to install npm -g on offline server

后端 未结 10 1269
谎友^
谎友^ 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 )

    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

提交回复
热议问题