🎁

git/wget/curl/cmd/pip/yum 如何开启代理加速下载

💡
Notion Tip: Use this page to describe your approach to interviewing product candidates.
 
 

git

临时
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
永久
git config --global --unset http.proxy
git config --global --unset https.proxy

wget

wget 有两种方式,一是永久代理,通过配置文件实现,而是一次性执行,直接命令行后面加上参数:
临时
wget -Y on -e "http_proxy=http://23.225.195.102:8886" http://example.com
永久
echo 'http_proxy=http://23.225.195.102:1080' > ~/.wgetrc
wget http://example.com

curl

临时
curl -x 127.0.0.1:1080 http://example.com
永久
echo '--proxy="127.0.0.1:1080"' >>~/.curlrc
curl http://example.com

cmd

set http_proxy=http://127.0.0.1:1080
set https_proxy=http://127.0.0.1:1080
上面命令的作用是设置环境变量,但只会持续到 cmd 窗口关闭,不是系统环境变量。

pip

pip --proxy=http://username:password@127.0.0.1:1080 install sunburnt

yum

echo "proxy=http://127.0.0.1:1080" >> /etc/yum.conf

apt

临时
export http_proxy=http://yourproxyaddress:proxyport
永久
这种方法要用到/etc/apt/文件夹下的apt.conf文件。如果您希望apt-get(而不是其他应用程序)一直使用http代理,您可以使用这种方式。 注意: 某些情况下,系统安装过程中没有建立apt配置文件。下面的操作将视情况修改现有的配置文件或者新建配置文件。 sudo vim /etc/apt/apt.conf 在您的apt.conf文件中加入下面这行(根据你的实际情况替换yourproxyaddress和proxyport)。
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
Acquire::ftp::proxy "ftp://127.0.0.1:8000/";
Acquire::https::proxy "https://127.0.0.1:8000/";
保存apt.conf文件。

全局

这种方法会在您的主目录下的.bashrc文件中添加两行。如果您希望apt-get和其他应用程序如wget等都使用http代理,您可以使用这种方式。 vim ~/.bashrc 在您的.bashrc文件末尾添加如下内容(根据你的实际情况替换yourproxyaddress和proxyport)。
export http_proxy=http://23.225.195.102:8765
保存文件。关闭当前终端,然后打开另一个终端。 记得关闭终端并重新打开,否自新的设置不会生效。