67

I'm working on an offline network and want to install angular-cli using npm. I have a zip file of angular-cli and using the latest node and npm version. I'm using the command: npm install ./angular-cli-master to install angular-cli from the folder. But I keep getting this error telling me I don't have an internet connection (which is ok). So how can I install this angular-cli while offline using the zip I downloaded from Github?

Thanks for your help.

earl-95
1834 silver badges12 bronze badges
asked Mar 28, 2017 at 8:14
7
  • Are you sure your archive contain every dependencies of angular-cli too? Commented Mar 28, 2017 at 10:15
  • Im not sure but now I see its trying to access registry.npmjs.org/webpack-merge. So I guess I have to use this file in order to use npm commands. Do you have any clue? Commented Mar 28, 2017 at 12:16
  • If you look at angular-cli's package.json you can see that webpack merge is a dependencies, you need to install all the dependencies before installing angular-cli. Since it is not installed, npm tries to get it from internet, and fail Commented Mar 28, 2017 at 12:37
  • Does it mean that I have to import all the dependencies to my closed network (offline network), "npm install" to the dependencies and then npm install angular-cli? Commented Mar 28, 2017 at 15:58
  • 1
    Yes, but simply copying the content of node_modules should be enought, unless you install globally. Another way that may be simpler is to run npm install angular-cli on a connected system, and copy the content of node_modules to the offline computer. Commented Mar 28, 2017 at 17:20

9 Answers 9

46

You simply copy the package and all dependencies in your node_modules folder, inside the project for local installation, or in the global folder (npm config get prefix to see where it is located) for a global installation.

The behavior of npm install is to check for the dependencies, and install them first. When it doesn't find them installed, nor the local file containing them, it tries to download them.

Since all of those steps fail (you don't have the dependency installed, it isn't available on the expected location, and it can't download it), the installation fails.

You can find the dependency list in the package.json of each module, but since it is recursive, it can take a long time to have everything set right if you do it manually, npm does it by recursion.

For you, the easiest way would be to create a new folder on the connected PC, and inside it npm install angular-cli, zip the folder and transfer it on the offline machine.


Late edit: If you need to industrialize this process, what you could also do is set up something like verdaccio (private npm server), download all dependencies so verdaccio populate its cache, and copy the cache to the airgapped server and run verdaccio there before installing.

One of the main pro of this method is that you will be able to reinstall as much as you want (as long as the cache is populated with the package), and packages that need native compilation will be able to be installed correctly too

answered Mar 28, 2017 at 12:43
Sign up to request clarification or add additional context in comments.

2 Comments

of course that might not work if your package builds native extensions
npm root -g to get the global node_modules path
33

Jan 2016 - check out Addy Osmani's recommendations for offline installation of npm packages

May 2017 - as of npm 5, you can pass the --prefer-offline flag to npm install

yarn does this out of the box.

KyleMit
31k74 gold badges517 silver badges713 bronze badges
answered May 30, 2017 at 14:25

Comments

6

In 2019, I found none recommended approaches were applicable to an "air gapped" server with no internet access.

I found the only solution was to, on windows, using artillery.io as an example:

  1. install the package on a machine with internet access, e.g local dev machine. npm install -g artillery
  2. Browse to C:\Users\{username}\npm
  3. zip up the \node_modules\artillery (e.g artillery.7z)
  4. Copy the zip and the files artillery, artillery.cmd (at root of npm folder) to the server
  5. Paste the two artillery, artillery.cmd to the root of the servers npm folder (C:\Users\{serverusername}\npm)
  6. Extract the zip to C:\Users\{serverusername}\npm\node_modules

This is the complicated version for just one tool. If your local machine's npm folder is relatively light on tools, you could always just zip the whole npm folder and copy + extract it on the server.

I still think it's odd that npm insists on trying to connect to the registry even when using npm pack and npm install -g <tarfile>

answered Nov 7, 2019 at 8:18

2 Comments

I use 'nvm' for windows and the install folder is different. Suggest using 'npm config get prefix' to determine.
the packages installed in {username}/npm contain path references to the machine where you install artillery globally. does it work regardless of having paths?
4

Problem: I'd been in similar situation where I can't install the express.js and all other dependencies specifies by package.json on my local machine (offline) using npm due to unavailability of internet connectivity.

Solution: I've a solution that works on Windows(not so sure of other platforms) through which I installed express framework with all the dependencies I required for my project which include cookie-parser, jade, morgan etc.


Steps :

  1. Install all the package(s) on a remote machine which has an internet access.
    In my case I'm using Windows on both remote as well as local machines and my requirement was of installation of express.js on local machine . So I run below command on my remote machine to install express.js

    C:\Users>npm install -g express-generator`
    
  2. After installation of express.js I created an app on my remote machine using:

    C:\Users\Name\Desktop>express Project`
    C:\Users\Name\Desktop\Project>npm install -g =>to install all other dependencies globally*
    
  3. Now browse to location where npm's global modules are stored, you can view the location by

    C:\Users>npm config get prefix
    

    Generally in Windows its

    C:\Users\{Username}\AppData\Roaming\
    
  4. Simply copy the npm and npm-cache folder of your remote machine.

  5. And place both copied folders viz. npm and npm-cache into your local machine on same location thats

    C:\Users\{Username}\AppData\Roaming\
    
answered Feb 6, 2020 at 18:24

1 Comment

i was successful without the cache folder. Also important is in the global install folder of first machine with internet make sure to copy the command files generated inside the npm folder (ie. depCheck.cmd )
2

the short answer, you can't. Most NPM packages such as @angular/cli need other dependencies and those need child dependencies which get installed when you run npm install

You can, however, install the cli when on the network and use it when offline.

answered Mar 28, 2017 at 14:01

2 Comments

I think thats what ill do. But there wont be missing files located in %appdata% (in the online pc) and I have to move this files too?
I don't think you need anything, once the cli is installed, it should work just fine and not need to connect to the internet. However, if you plan on creating new projects with ng new PROJ NAME you'll need internet because that project itself needs to install dependencies. You should be fine if only using ng build, generate and others.
0

You can find the npm install command documentation here: https://docs.npmjs.com/cli/install

I am not quite sure and unfortunately, I do not have the chance to test it myself right now, but I would try to either unzip the folder and remove the dot, like that: npm install /angular-cli-master (= installing a folder not a zip file) or just add the zip file ending like that: npm install ./angular-cli-master.tgz
(= installing a zip-file not a folder, file ending may be .zip or something else, though)

answered Mar 28, 2017 at 8:25

Comments

0

Was test success with node 18.x.x.

The following step guild how to install http-server package

  • On Online PC: npm install -g http-server After finish install, copy http server folder. (Usually locate at: C:\Users[UserName]\AppData\Roaming\npm\node_modules)
  • On offline PC:
    • Paste http-server folder. e.g. D:\http-server
    • npm install -g D:\http-server
answered Nov 18, 2022 at 7:16

Comments

0

There is a package called onmi in npm This is what is written in its description

Offline Node Module installer - cli tool for installing Node modules and their dependencies from any project or pre-installed local modules, without an internet connection

answered Jan 17, 2025 at 15:17

Comments

-2

Online computer:

npm install -g offline-npm

copy the npm-module to the offline computer and thats it !

answered Jun 16, 2021 at 12:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.