├── .github └── workflows │ └── toc.yml └── README.md /.github/workflows/toc.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | name: TOC Generator 3 | jobs: 4 | generateTOC: 5 | name: TOC Generator 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: technote-space/toc-generator@v4 9 | with: 10 | TOC_TITLE: "**目录**" 11 | MAX_HEADER_LEVEL: 2 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # package manager proxy settings 2 | 3 | 如果你的包管理器想直接使用优秀的镜像仓库,请参考这个:[Thanks-Mirror](https://github.com/eryajf/Thanks-Mirror) 4 | 5 | 6 | 7 | **目录** 8 | 9 | - [pip](#pip) 10 | - [git](#git) 11 | - [cargo](#cargo) 12 | - [apt (apt-get)](#apt-apt-get) 13 | - [curl](#curl) 14 | - [Gradle](#gradle) 15 | - [Maven](#maven) 16 | - [go get](#go-get) 17 | - [npm](#npm) 18 | - [rustup](#rustup) 19 | - [yarn](#yarn) 20 | - [yarn2](#yarn2) 21 | - [gem](#gem) 22 | - [brew](#brew) 23 | - [wget](#wget) 24 | - [snap](#snap) 25 | - [docker](#docker) 26 | - [Electron Dev Dependency](#electron-dev-dependency) 27 | - [Visual Studio Code Remote (WSL2)](#visual-studio-code-remote-wsl2) 28 | - [Visual Studio Code Remote (SSH)](#visual-studio-code-remote-ssh) 29 | - [Tips](#tips) 30 | - [Scoop](#scoop) 31 | - [OpenWRT opkg](#openwrt-opkg) 32 | - [Chocolatey](#chocolatey) 33 | - [Guix](#guix) 34 | - [FAQ](#faq) 35 | 36 | 37 | 38 | ## pip 39 | ~/.config/pip/pip.conf 40 | ``` 41 | [global] 42 | proxy=http://localhost:1087 43 | ``` 44 | 注意不支持socks5 45 | ### Reference 46 | * https://my.oschina.net/tangshi/blog/699190 47 | 48 | ## git 49 | ### clone with ssh 50 | 在 文件 `~/.ssh/config` 后添加下面两行 51 | ```bash 52 | Host github.com 53 | # Mac下 54 | ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p 55 | # Linux下 56 | ProxyCommand nc --proxy-type socks5 --proxy 127.0.0.1:1080 %h %p 57 | ``` 58 | 59 | 注意Linux和Mac下ncat/netcat区别,详见https://unix.stackexchange.com/questions/368155/what-are-the-differences-between-ncat-nc-and-netcat 60 | 61 | ### clone with http 62 | ``` 63 | git config --global http.proxy http://127.0.0.1:1087 64 | ``` 65 | 66 | ### Reference 67 | https://gist.github.com/laispace/666dd7b27e9116faece6 68 | 69 | ## cargo 70 | Cargo 会依次检查以下位置 71 | 1. 环境变量 `CARGO_HTTP_PROXY` 72 | ```bash 73 | export CARGO_HTTP_PROXY=http://127.0.0.1:1080 74 | ``` 75 | 2. [任意 `config.toml`](https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure) 中的 `http.proxy` 76 | ```toml 77 | [http] 78 | proxy = "127.0.0.1:1080" 79 | ``` 80 | 3. 环境变量 `HTTPS_PROXY` & `https_proxy` & `http_proxy` 81 | ```bash 82 | export https_proxy=http://127.0.0.1:1080 83 | export http_proxy=http://127.0.0.1:1080 84 | ``` 85 | `http_proxy` 一般来讲没必要,除非使用基于 HTTP 的 Crate Repository 86 | 87 | Cargo 使用 libcurl,故可接受任何符合 [libcurl format](https://everything.curl.dev/usingcurl/proxies) 的地址与协议 88 | 89 | ( `127.0.0.1:1080` , `http://127.0.0.1:1080`, `socks5://127.0.0.1:1080` )均可 90 | 91 | ### Reference 92 | https://doc.rust-lang.org/cargo/reference/config.html#httpproxy 93 | 94 | ## apt (apt-get) 95 | 在 `/etc/apt/apt.conf.d/` 目录下新增 `proxy.conf` 文件,加入: 96 | ``` 97 | Acquire::http::Proxy "http://127.0.0.1:8080/"; 98 | Acquire::https::Proxy "http://127.0.0.1:8080/"; 99 | ``` 100 | 如果希望使用 Socks5 代理,则加入: 101 | ``` 102 | Acquire::http::Proxy "socks5h://127.0.0.1:8080/"; 103 | Acquire::https::Proxy "socks5h://127.0.0.1:8080/"; 104 | ``` 105 | 106 | ### Reference 107 | https://askubuntu.com/a/349765/883355 108 | https://github.com/lanlin/notes/issues/109 109 | 110 | ## curl 111 | ```bash 112 | socks5 = "127.0.0.1:1080" 113 | ``` 114 | add to `~/.curlrc` 115 | 116 | ### Reference 117 | https://www.zhihu.com/question/31360766 118 | 119 | ## Gradle 120 | 这个浪费了好长时间额 121 | ~/.gradle/gradle.properties 122 | ``` 123 | systemProp.http.proxyHost=127.0.0.1 124 | systemProp.http.proxyPort=1087 125 | systemProp.https.proxyHost=127.0.0.1 126 | systemProp.https.proxyPort=1087 127 | ``` 128 | ### Reference 129 | https://stackoverflow.com/questions/5991194/gradle-proxy-configuration 130 | 131 | ## Maven 132 | %Maven 安装目录%/conf/settings.xml 133 | ```xml 134 | 139 | 140 | 154 | 155 | proxy 156 | true 157 | http 158 | 127.0.0.1 159 | 1087 160 | 161 | 162 | ``` 163 | 164 | ### Reference 165 | [https://maven.apache.org/guides/mini/guide-proxies.html](https://maven.apache.org/guides/mini/guide-proxies.html) 166 | 167 | ## go get 168 | ``` 169 | HTTP_PROXY=socks5://localhost:1080 go get 170 | ``` 171 | 测试了下HTTPS_PROXY和ALL_PROXY都不起作用 172 | 173 | OR使用[goproxy.io](https://goproxy.io/) 174 | 175 | ## npm 176 | ``` 177 | npm config set proxy http://127.0.0.1:1087 178 | npm config set https-proxy http://127.0.0.1:1087 179 | ``` 180 | 用socks5就报错- - 181 | 182 | 推荐使用yarn,npm是真的慢 183 | 184 | ### reference 185 | * https://stackoverflow.com/questions/7559648/is-there-a-way-to-make-npm-install-the-command-to-work-behind-proxy 186 | * 有些包要在 postinstall 阶段下载内容的还需要配置环境变量 https://antfu.me/posts/npm-binary-mirrors 187 | 188 | ## rustup 189 | ```bash 190 | export https_proxy=http://127.0.0.1:1080 191 | ``` 192 | 废物中国电信,不挂代理慢如龟 193 | 194 | ## yarn 195 | ``` 196 | yarn config set proxy http://127.0.0.1:1087 197 | yarn config set https-proxy http://127.0.0.1:1087 198 | ``` 199 | 不支持socks5 200 | 201 | ### Reference 202 | https://github.com/yarnpkg/yarn/issues/3418 203 | 204 | ## yarn2 205 | [Yarn 2+ - Official](https://yarnpkg.com/) 206 | 207 | ```sh 208 | yarn config set httpProxy http://127.0.0.1:1087 209 | yarn config set httpsProxy http://127.0.0.1:1087 210 | ``` 211 | **不支持全局设置** 212 | 支持socks5 213 | 214 | 提示: 这个命令会修改项目目录下的`.yarnrc.yml`文件, 请留意不要把带有如: 215 | ```yml 216 | httpsProxy: "socks5://127.0.0.1:1080" 217 | ``` 218 | 的代码提交到仓库, 以免造成麻烦 219 |
220 | 建议使用npm镜像而不是配置使用代理 221 | 222 | ```sh 223 | yarn config set npmRegistryServer https://127.0.0.1:1087 224 | ``` 225 | 注意: 此方法不适用于下载yarn官方插件! 226 | yarn的官方插件默认会从GitHub(raw.githubusercontent.com)上下载 227 | 您可能依旧需要配置代理 228 |
229 | 230 |
231 | 232 | 233 | ### Reference 234 | 235 | 236 | - [yarn doc - httpProxy](https://yarnpkg.com/configuration/yarnrc#httpProxy) 237 | - [yarn doc - httpsProxy](https://yarnpkg.com/configuration/yarnrc#httpsProxy) 238 |
239 | 240 | ## gem 241 | ~/.gemrc 242 | ``` 243 | --- 244 | # See 'gem help env' for additional options. 245 | http_proxy: http://localhost:1087 246 | ``` 247 | ### reference 248 | * google 249 | 250 | ## brew 251 | ``` 252 | ALL_PROXY=socks5://localhost:1080 brew ... 253 | ``` 254 | 255 | ## wget 256 | ``` 257 | use_proxy=yes 258 | http_proxy=127.0.0.1:1087 259 | https_proxy=127.0.0.1:1087 260 | ``` 261 | ~/.wgetrc 262 | 263 | ### Reference 264 | * https://stackoverflow.com/questions/11211705/how-to-set-proxy-for-wget 265 | 266 | 267 | ## snap 268 | ```bash 269 | sudo snap set system proxy.http="http://127.0.0.1:1087" 270 | sudo snap set system proxy.https="http://127.0.0.1:1087" 271 | ``` 272 | 273 | ### Reference 274 | https://askubuntu.com/questions/764610/how-to-install-snap-packages-behind-web-proxy-on-ubuntu-16-04#answer-1146047 275 | 276 | 277 | ## docker 278 | ``` 279 | $ sudo mkdir -p /etc/systemd/system/docker.service.d 280 | $ sudo vim /etc/systemd/system/docker.service.d/proxy.conf 281 | 282 | [Service] 283 | Environment="ALL_PROXY=socks5://localhost:1080" 284 | 285 | $ sudo systemctl daemon-reload 286 | $ sudo systemctl restart docker 287 | ``` 288 | 289 | 必须是socks5,http不生效 290 | 291 | ## Electron Dev Dependency 292 | 设置环境变量 293 | ``` 294 | ELECTRON_GET_USE_PROXY=true 295 | GLOBAL_AGENT_HTTPS_PROXY=http://localhost:1080 296 | ``` 297 | ### References 298 | * https://www.electronjs.org/docs/latest/tutorial/installation#proxies 299 | * https://github.com/gajus/global-agent/blob/v2.1.5/README.md#environment-variables 300 | 301 | ## Visual Studio Code Remote (WSL2) 302 | 303 | WSL2环境下可以通过设置`~/.vscode-server/server-env-setup`脚本文件,设置开发环境的环境变量,使用代理。 304 | 305 | WSL2内环境访问Win下的代理程序端口代理(例子代码中http代理端口监听17070),因为子网地址每次启动都不一样,需要动态处理。 306 | 307 | 新建`~/.vscode-server/server-env-setup`文件,该文件会在VSCode启动WSL环境后被`source`。 308 | 309 | ``` 310 | WSL_HOST=$(sed -n '/^nameserver/p' /etc/resolv.conf | cut -d' ' -f2) 311 | export http_proxy=http://${WSL_HOST}:17070 312 | export https_proxy=$http_proxy 313 | export all_proxy=$http_proxy 314 | ``` 315 | 316 | ### References 317 | * https://code.visualstudio.com/docs/remote/wsl 318 | 319 | ## Visual Studio Code Remote (SSH) 320 | 321 | VSCode SSH后的环境不会使用本地界面VSCode内的代理设置,如果SSH主机没有默认网络链接或在墙内,会导致问题。 322 | 323 | ### SSH主机无网络 324 | 325 | 需要手动下载vscode 的server端传输部署。详情见链接 326 | 327 | * https://stackoverflow.com/questions/56671520/how-can-i-install-vscode-server-in-linux-offline 328 | * https://gist.github.com/b01/0a16b6645ab7921b0910603dfb85e4fb 329 | 330 | ### SSH主机在墙内 331 | 332 | 虽然文档未提及,但是可以使用WSL模式的方案,配置`~/.vscode-server/server-env-setup`文件设置代理。 333 | 334 | SSH主机有代理程序监听在17070端口: 335 | 336 | 新建`~/.vscode-server/server-env-setup`文件,该文件会在VSCode启动WSL环境后被source。 337 | ``` 338 | export http_proxy=http://127.0.0.1:17070 339 | export https_proxy=$http_proxy 340 | export all_proxy=$http_proxy 341 | ``` 342 | 343 | ### References 344 | * https://code.visualstudio.com/docs/remote/ssh 345 | 346 | ## Tips 347 | 推荐使用Clash,[windows版](https://github.com/Fndroid/clash_for_windows_pkg),[mac版](https://github.com/yichengchen/clashX)(注意:[ClashX Pro](https://install.appcenter.ms/users/clashx/apps/clashx-pro/distribution_groups/public) 包含TUN功能,ClashX不包含),开启Tun mode可以解决大部分的GFW问题 348 | 349 | ### Reference 350 | https://docs.cfw.lbyczf.com/contents/tun.html 351 | 352 | 353 | ## Scoop 354 | ```bash 355 | scoop config proxy 127.0.0.1:1080 356 | ``` 357 | 358 | ### Reference 359 | * https://github.com/ScoopInstaller/Scoop/wiki/Using-Scoop-behind-a-proxy#configuring-scoop-to-use-your-proxy 360 | 361 | ## OpenWRT opkg 362 | 在LUCI面版菜单配置或者/etc/opkg.conf末尾追加 363 | ``` 364 | option http_proxy http://localhost:1080/ 365 | ``` 366 | 367 | ### References 368 | https://openwrt.org/docs/guide-user/additional-software/opkg 369 | 370 | ## Chocolatey 371 | 372 | 从0.9.9.9版本开始,choco支持在配置文件显式配置代理。 373 | ``` 374 | # 设置代理 375 | choco config set proxy http://localhost:8888 376 | # 取消代理 377 | choco config unset proxy 378 | ``` 379 | 除此之外,从0.10.4版本开始,`choco`会自动寻找`http_proxy`和`https_proxy`或者`noproxy`环境变量,通过在命令行临时设置环境变量的方式也可以方便调整`choco`的代理设置。 380 | 381 | ### Reference 382 | * https://docs.chocolatey.org/en-us/guides/usage/proxy-settings-for-chocolatey#explicit-proxy-settings 383 | 384 | 385 | ## Guix 386 | Guix daemon honors `http_proxy` and `https_proxy` environment variables. 387 | 388 | ### With Shepherd 389 | ``` 390 | # Set 391 | herd set-http-proxy guix-daemon http://localhost:1080 392 | 393 | # Clean 394 | herd set-http-proxy guix-daemon 395 | ``` 396 | 397 | ### Manually or with other service supervisors 398 | ``` 399 | http_proxy="http://localhost:1080" 400 | env http_proxy="${http_proxy}" https_proxy="${http_proxy}" guix-daemon --build-users-group=guixbuild 401 | ``` 402 | 403 | ### Reference 404 | * https://guix.gnu.org/en/manual/devel/en/guix.html#Proxy-Settings 405 | * https://guix.gnu.org/en/manual/devel/en/guix.html#index-guix_002dconfiguration 406 | 407 | ## FAQ 408 | 409 | 如果希望在`root`下使用代理,需要使用`visudo`修改`/etc/sudoers`文件 410 | ``` 411 | Defaults env_reset 412 | # 新增下行 413 | Defaults env_keep="http_proxy https_proxy ftp_proxy no_proxy DISPLAY XAUTHORITY" 414 | ``` 415 | 416 | ### Reference 417 | * https://www.chenyudong.com/archives/sudo-keep-env.html 418 | --------------------------------------------------------------------------------