How to install npm -g on offline server

后端 未结 10 1259
谎友^
谎友^ 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:43

    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

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

    List the dependencies in bundledDependencies in your package.json, and then run npm pack to create a tarball. Get that over to the other machine, and either npm install <tarball>, or just crack it open manually.

    https://github.com/npm/npm/issues/1349

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

    npmbox is outdated

    Use npm pack command (npm docs), no need to install anything.

    Single package

    If you want only one package (for example, forever), you can run:

    npm pack forever
    

    this command will fetch it to the cache, and then copy the tarball to the current working directory as -.tgz

    Then, from the folder you created the package, you install it with:

    npm install -g ./forever-x.y.z.tgz
    

    Whole project

    If you want a whole project to be installed offline, include a poperty in your package.json named bundleDependencies and list all dependecies you need in this field.

    // package.json
    
    "dependencies": {
      "archiver": "^2.1.1",
      "axios": "^0.16.2",
      "body-parser": "^1.18.3"
    },
    "bundleDependencies": {
      "archiver": "^2.1.1",
      "axios": "^0.16.2",
      "body-parser": "^1.18.3"
    }
    

    Then run npm pack.

    It will create a .tgz file of your whole project and dependencias.

    You just have to copy it to the offline server and untar.

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

    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>
    
    0 讨论(0)
提交回复
热议问题