Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install the source when there is no network #1154

Closed
lihy87 opened this issue Mar 23, 2017 · 24 comments
Closed

How to install the source when there is no network #1154

lihy87 opened this issue Mar 23, 2017 · 24 comments
Labels

Comments

@lihy87
Copy link

lihy87 commented Mar 23, 2017

the target machine(ubuntu 16.04) has no network, how do i install it in source?

@bnoordhuis
Copy link
Member

Copy over the source tarball from nodejs.org and pass --tarball <location> to node-gyp or npm.

@lihy87
Copy link
Author

lihy87 commented Mar 24, 2017

Could you write the detailed steps?

@bnoordhuis
Copy link
Member

That's really all there is to it. If anything specific is unclear, let me know and I'll try to clarify.

@gibfahn
Copy link
Member

gibfahn commented Mar 24, 2017

the target machine(ubuntu 16.04) has no network, how do i install it in source?

Are you trying to install node-gyp or node itself? Do you just want to npm install native modules?

If you've installed node and npm you already have node-gyp installed (it's a dependency of npm), you just need the headers.

Assuming you're using node v6.10.1:

Headers are stored in ~/.node-gyp/6.10.1/, you also need the installVersion file. In later versions of node-gyp these files could change, check the contents of ~/.node-gyp on a machine with internet access when you run npm i -g node-gyp && node-gyp configure and duplicate it.

curl -O https://nodejs.org/dist/v6.10.1/node-v6.10.1-headers.tar.gz # on a computer with internet
# Copy header tarball to offline machine
mkdir -p  ~/.node-gyp/6.10.1
tar -xf node-v6.10.1-headers.tar.gz --directory ~/.node-gyp/6.10.1/ --strip-components 1
echo 9 >~/.node-gyp/6.10.1/installVersion

This should be enough for the common use case, if you need something more specific please provide some actual information about what you want to do.

@bdharrington7
Copy link

Not sure if this is related or not, but I have a dependency (better-sqlite3) that has a compilation step that uses node-gyp to compile. For reasons I don't quite understand, the header files are downloaded when this compilation phase is kicked off for the first time. When this module is compiled, a folder is created at $HOME/.node-gyp that contains the header files that are downloaded, and includes a installVersion file containing the number 9 only.

When I run npm install -g node-gyp && node-gyp ./tarball.tar.gz, this folder doesn't show up at all. I've also tried npm install --tarball ./tarball.tar.gz and node-gyp --tarball ./tarball.tar.gz

node v8.1.2
npm v5.0.3

@bnoordhuis
Copy link
Member

@bdharrington7 The tarball that node-gyp downloads contains the node.js SDK (this file), it's not related to the tarball that npm downloads from its registry when you install a package.

If you download the SDK tarball manually, invoke node-gyp like this from inside the directory that contains the add-on you want to build (with a binding.gyp in it):

$ node-gyp --tarball /path/to/node-x.y.z-headers.tar.gz rebuild

@bdharrington7
Copy link

The issue I'm trying to solve for is that the directory that contains the add-on I want to build doesn't exist at the time I want to install the headers. I'm trying to preemptively provide these headers in the expected location so that when npm install is run, it doesn't try to go out and fetch the headers.

A little more insight on the problem: I'm trying to create a development environment in Docker that works offline. As such, since the npm install layer is re-built when something in package.json changes, the installation of the node-gyp headers is no longer present in the expected location, and is subsequently re-downloaded.

@bnoordhuis
Copy link
Member

node-gyp install will do that for you; node-gyp install --ensure to only download them when not already present.

@gibfahn
Copy link
Member

gibfahn commented Jul 4, 2017

node-gyp install will do that for you; node-gyp install --ensure to only download them when not already present.

--ensure is on by default unless you're using --tarball IIRC

EDIT: lib/configure.js#L77

@abhagupta
Copy link

@bdharrington7 did you get past this problem in your docker container?

@bdharrington7
Copy link

Yeah, I download and place the header files like this, but you’ll have to figure out where to get the binary, I’m getting them from an internal repo.

ENV NODE_VERSION v8.9.4
ENV NODE_FILENAME node-${NODE_VERSION}-linux-x64.tar.gz
ENV NODE_URL https://${SOMEREPO}.com/node-distributions/${NODE_VERSION}/${NODE_FILENAME}

RUN wget -nv "${NODE_URL}" -O "/tmp/${NODE_FILENAME}" && \
    tar xf "/tmp/${NODE_FILENAME}" -C /usr/local/ --strip=1 && \
    rm "/tmp/${NODE_FILENAME}"

@abhagupta
Copy link

How did you do the npm install to make sure your dependencies are loading node-gyp without needing internet connection?

@bdharrington7
Copy link

I store my dependencies in source control (the non-compiled ones) so I turn off WiFi and run npm rebuild

@nickboldt
Copy link

Simpler solution in #1133 (comment):

NODE_VER=v10.14.1
curl -sSL https://nodejs.org/download/release/${NODE_VER}/node-${NODE_VER}-headers.tar.gz \
        -o /tmp/node-headers.tgz; \
npm config set tarball /tmp/node-headers.tgz

@Maxim-Mazurok
Copy link

Windows users, beware:
As mentioned here,

on Windows --tarball is useless because node-gyp subsequently wants to download the node.lib file

@NexZhu
Copy link

NexZhu commented Dec 26, 2022

npm conifg set tarball is no longer working for Node.js 19.3.0 and npm 9.2.0

[root@Nogard baas]# npm config set tarball /tmp/headers.tar
npm ERR! `tarball` is not a valid npm option

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-12-26T15_23_07_615Z-debug-0.log

Anyone know any alternative solution?

@cclauss
Copy link
Contributor

cclauss commented Jun 1, 2023

export GYP_TARBALL=/node/node-headers.tar.gz

@cclauss cclauss added the tarball label Jun 1, 2023
@pcurrivan
Copy link

GYP_TARBALL does not work with Node v18.16.1 and NPM v9.3.1. gyp still tries to download the headers from nodejs.org:
gyp http GET https://nodejs.org/download/release/v18.16.1/node-v18.16.1-headers.tar.gz

@robingood556
Copy link

@pcurrivan did you solved this problem?

@chj-damon
Copy link

@pcurrivan have you solved this problem?

@robingood556
Copy link

@chj-damon i solved my problem using env var - NODEJS_ORG_MIRROR

@chj-damon
Copy link

@robingood556 can you share how you did it? thanks

@robingood556
Copy link

@chj-damon add ENV in my Dockerfile

@pcurrivan
Copy link

pcurrivan commented Aug 24, 2023

It seems like the tarball NPM option does actually still work, you just can't set it with "npm config set", Adding it manually to .npmrc or using the env var npm_config_tarball seems to still work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests