常用的包管理配置加速和网络代理

2024-09-29 19:55:00
丁国栋
原创 423
摘要:由于npm、yarn这些默认的包管理仓库在国外,因此下载和安装很慢,需要加速。本文整理了一些常用的加速配置,以及网络代理设置。

由于npm、yarn这些默认的包管理仓库在国外,因此下载和安装很慢,需要加速。本文整理了一些常用的加速配置,以及网络代理设置。


加速配置

npm配置registry

npm config set registry http://mirrors.cloud.tencent.com/npm/
npm config get registry

npm配置registry

yarn config set registry http://mirrors.cloud.tencent.com/npm/
yarn config get registry

yarn清除缓存、编译

yarn cache clean
yarn build

包管理仓库的镜像站有很多,例如清华的Tuna,腾讯云、华为云、阿里云等都有镜像站。


常用网络代理设置


1. socks5转http代理

假设你有一个socks5代理服务器 socks5://10.8.1.7:3127,为了给npm使用,需要将其转换为http代理,可以使用 npm 的 http-proxy-to-socks 包实现。

npm install --location=global http-proxy-to-socks
hpts -s 10.8.1.7:3127 -p 1080
npm config set proxy http://127.0.0.1:1080
npm config set https-proxy http://127.0.0.1:1080
npm config set strict-ssl false

取消代理设置

npm config delete proxy
npm config delete https-proxy

2. Maven 配置使用socks5代理

export MAVEN_OPTS="-DsocksProxyHost=10.8.1.7 -DsocksProxyPort=3127"

3. curl 设置socks5代理

curl -fsSL --proxy socks5://10.8.1.7:3127 

4. Linux会话级代理设置(仅在当前shell会话有效)

export {ALL,HTTP,HTTPS}_PROXY=socks5://10.8.1.7:3127
取消代理设置
unset {ALL,HTTP,HTTPS}_PROXY
unset ALL_PROXY; unset http_proxy; unset https_proxy

5. Debian/Ubuntu Linux apt 代理

参考本文《如何在使用apt安装软件包时临时设置使用代理

sudo apt install --upgrade -o Acquire::http::proxy="socks5h://10.0.0.8:3127/" PACKAGE 

注:如果是https协议或者http协议,将 socks5h 更换为https或http即可。

--

发表评论
博客分类