常见Linux软件设置代理方法

因为有些软件源不设代理实在太慢,所以这里记一下Linux上常见软件设置代理的方法。

获取代理监听ip和端口

在WSL上获取主机ip是:

Terminal window
cat /etc/resolv.conf

端口看你电脑设置。

git设置代理

永久方法

Terminal window
git config --global http.proxy <protocol>://<host>:<port>
git config --global https.proxy <protocol>://<host>:<port>

临时方法

Terminal window
git -c http.proxy=<protocol>://<host>:<port> clone https://github.com/<user>/<repository>.git

wget设置代理

永久方法

Terminal window
echo "http_proxy=<protocol>://<host>:<port>" >> ~/.wgetrc
echo "https_proxy=<protocol>://<host>:<port>" >> ~/.wgetrc

临时方法

Terminal window
wget --proxy-user=<username> --proxy-password=<password> -e use_proxy=yes -e http_proxy=<protocol>://<host>:<port> <url>

curl设置代理

永久方法

Terminal window
echo "export http_proxy=<protocol>://<host>:<port>" >> ~/.bashrc
echo "export https_proxy=<protocol>://<host>:<port>" >> ~/.bashrc
source ~/.bashrc

临时方法

Terminal window
curl -x <protocol>://[username:password@]<host>:<port> <url>

apt设置代理

永久方法

Terminal window
sudo echo "Acquire::http::Proxy \"http://[username:password@]<host>:<port>/\";" > /etc/apt/apt.conf
sudo echo "Acquire::https::Proxy \"https://[username:password@]<host>:<port>/\";" >> /etc/apt/apt.conf
sudo apt update

临时方法

Terminal window
sudo apt-get -o Acquire::http::proxy="https://[username:password@]<host>:<port>" update

conda设置代理

Terminal window
conda config --set proxy_servers.http http://[username:password@]<host>:<port>
conda config --set proxy_servers.https https://[username:password@]<host>:<port>

分类: