搭建npm私有仓库
访问https://github.com/nvm-sh/nvm#installing-and-updating。在verdaccio的配置文件中添加listen: 0.0.0.0:4873如果不添加只能本机能访问。至此npm私有仓库就搭建完毕,如果你想要在内网电脑上使用npm,首先需要在内网电脑上安装 node.js。把环境变量写入到 ~/.bash_profile中 ,在source~/.bas
GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions访问nvm/README.md at master · nvm-sh/nvm · GitHub
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
两者任选其一,复制到终端上
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
把环境变量写入到 ~/.bash_profile 中 ,在source ~/.bashrc
用nvm -v 查看版本
# nvm -v
0.39.3
2.安装verdaccio
把下面的命令复制到终端上
npm install --location=global verdaccio@next
也可以用npm进行全局安装
npm install -g verdaccio
在verdaccio的配置文件中添加 listen: 0.0.0.0:4873 如果不添加只能本机能访问
# grep '0.0.0.0' /root/.config/verdaccio/config.yaml |grep -Ev '^#'
listen: 0.0.0.0:4873
3.安装pm2
npm i -g pm2
-g表示全局安装
启动 verdaccion
pm2 start verdaccion
直接运行,这里建议采用tmux分屏处理,可以一边看日志一边操作
verdaccion
关闭防火墙,或者开放4873端口
systemctl stop firewalld
or
firewall-cmd --zone-public --add-port=4873/tcp --permanent
firewall-cmd --reload
浏览器输入IP:4873,就可以直接访问verdaccio了
可以通过publish把包发到仓库
安装nrm
npm i -g nrm
通过nrm添加私有仓库
nrm add xx http://本机ip:4873
xx为私有仓库的名字
进入私有库
nrm use xx
更换为taobao源
nrm use taobao
可以通过nrm ls列出当前可用的仓库
# nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
xx ------ http://本机ip:4873/
至此npm私有仓库就搭建完毕,如果你想要在内网电脑上使用npm,首先需要在内网电脑上安装 node.js
下载完成后可以通过scp传送到内网电脑
内网电脑安装 node.js步骤
VERSION=v10.15.0 #改成你的版本
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs #改成你的版本
设置全局变量
# vim .bashrc
export PATH=/usr/local/lib/nodejs/node-v18.16.1-linux-x64/bin:$PATH
设置npm源
npm config set registry "http://npmip:4873/"
设置完之后
cat .npmrc
registry=http://npm的ip:4873/
至此内网电脑用npm下载就直接从外网的npm源上拉取包了
更多推荐
所有评论(0)