[英]Nodejs and npm module offline installation
I work in company that has some corporate proxy.我在有一些公司代理的公司工作。 I am able to install nodejs but I cannot install any npm module at all.
我能够安装 nodejs,但我根本无法安装任何 npm 模块。 I tried alot things, different proxy settings but none of them worked.
我尝试了很多东西,不同的代理设置,但都没有奏效。 Nodejs simply can't connect to internet to fetch modules I need.
Nodejs 根本无法连接到互联网来获取我需要的模块。 Basically Im trying to setup Cordova and Ionic on this computer.
基本上我试图在这台计算机上设置 Cordova 和 Ionic。
I was wondering if there any way to offline install it?我想知道是否有任何方法可以离线安装它? I meant, is there any way to bring these files in USB drive or something and then install it?
我的意思是,有没有办法把这些文件放在 USB 驱动器或其他东西中,然后安装它?
It is possible or not?有没有可能?
Thank you Guys:)感谢你们:)
Yes, you can use Yarn to install packages without an internet connection. 是的,您可以使用纱线来安装没有互联网连接的包。
For example, to install ionic
and cordova
globally: 例如,要在全球范围内安装
ionic
和cordova
:
On the internet machine (configure local cache location): 在Internet机器上(配置本地缓存位置):
yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
On the offline machine (configure local cache location): 在脱机计算机上(配置本地缓存位置):
yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
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>
) (或者使用
yarn config set prefix <file_path>
设置它)
On the offline machine, add it to your path. 在脱机计算机上,将其添加到路径中。 Eg:
例如:
echo 'export PATH=$PATH:'"$(yarn global bin)" >> ~/.bashrc source ~/.bashrc # reload
On the internet machine, download ionic
's and cordova
's dependencies: 在互联网机器上,下载
ionic
和cordova
的依赖:
mkdir new-cli-ionic-cordova/ cd new-cli-ionic-cordova/ yarn add ionic cordova
Then copy new-cli-ionic-cordova/yarn.lock
and ~/yarn-offline-mirror/
to the offline machine. 然后将
new-cli-ionic-cordova/yarn.lock
和~/yarn-offline-mirror/
复制到离线机器。 ( rm -rf new-cli-ionic-cordova/
is ok now.) (
rm -rf new-cli-ionic-cordova/
现在好了。)
On the offline machine, install ionic
and cordova
from local cache: 在离线计算机上,从本地缓存安装
ionic
和cordova
:
cp /path/to/imported/yarn.lock . cp -n /path/to/imported/yarn-offline-mirror/* ~/yarn-offline-mirror/ yarn global add --offline ionic cordova rm -f ./yarn.lock
You can also install packages as dependencies for a single project using a similar process. 您还可以使用类似的过程将包安装为单个项目的依赖项。 For more info, see my post here: https://assafmo.github.io/2018/04/11/yarn-offline.html
有关详细信息,请参阅我的帖子: https : //assafmo.github.io/2018/04/11/yarn-offline.html
first I would try to get the npm-config working for your proxy. 首先,我会尝试让npm-config适用于您的代理。 Talk to your IT how to connect to the https://www.npmjs.com/package/ registry .
与您的IT部门联系,了解如何连接到https://www.npmjs.com/package/ 注册表 。 Probably these links can be helpful (just in case you didn't find them yet):
可能这些链接可能会有所帮助(以防您还没有找到它们):
Probably you can post the logging output and someone can help you. 可能你可以发布日志输出,有人可以帮助你。
Only if this fails, I'd think about setting up a local package registry . 只有在失败的情况下,我才考虑设置本地包注册表 。 Probably Sinopia can help you.
可能Sinopia可以帮到你。 But...:
但...:
Any other thoughts? 还有其他想法吗?
You can get npm to work behind a proxy to solve the problem. 您可以让npm在代理后面工作以解决问题。 For this, it is important to set both HTTP_PROXY and HTTPS_PROXY environment variables.
为此,设置HTTP_PROXY和HTTPS_PROXY环境变量非常重要。
For HTTP_PROXY you can use 对于HTTP_PROXY,您可以使用
npm config set proxy http://proxy_host:port
For HTTPS_PROXY you can try this one 对于HTTPS_PROXY,您可以尝试这个
npm config set https-proxy http://proxy.company.com:8080
step1: download nodejs: https://nodejs.org/en/download/ step1:下载nodejs: https://nodejs.org/en/download/
step2: tar xvf node-v16.17.0-linux-x64.tar.xz
第二步:
tar xvf node-v16.17.0-linux-x64.tar.xz
step3: add to env:第三步:添加到环境中:
vim /etc/profile.d/nodejs.sh:
#!/bin/sh
export PATH=/YOUR-PATH-TO/node-v12.16.2-linux-s390x/bin:$PATH
or
vim ~/.bash_profile:
export PATH=/YOUR-PATH-TO/node-v12.16.2-linux-s390x/bin:$PATH
method 1:方法一:
on machine A which has internet access:
npm install all the packages needed
upload the node_modules/* to /YOUR-PATH-TO/node-v12.16.2-linux-s390x/lib/node_modules/
method 2:方法二:
on machine A which has internet access:
>npm install -g npm-bundle
>npm install -g eslint
>npm-bundle eslint
eslint-7.8.1.tgz
on the target machine which has no internet access:
>npm install -g ./eslint-7.8.1.tgz
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.