在公司的电脑只能通过设置代理访问外网时,需要设置代理
命令行CMD代理设置
代理不需要密码时,在命令行界面输入:
set http_proxy=http://proxy_ip_or_fqdn:8080
代理需要用户密码时,在命令行界面输入:
如果代理服务器需要用户名和密码的话,那么需要做如下设置:
set http_proxy_user=
set http_proxy_pass=
或者
set http_proxy=http://proxy_user:proxy_password@proxy_ip_or_fqdn:8080
Git代理设置
类似,git设置代理如下:
git config --global http.proxy http://proxy_ip_or_fqdn:8080
git config --global http.proxy http://proxy_user:proxy_password@proxy_ip_or_fqdn:8080
设置完成后,可以通过如下命令来查看设置是否生效:
git config --get --global http.proxy
删除代理设置,使用:
git config --global --unset http.proxy
NPM代理设置
npm设置代理方法如下:
npm config set proxy=http://proxy_ip_or_fqdn:8080
npm config set proxy=http://proxy_user:proxy_password@proxy_ip_or_fqdn:8080
Bower代理设置
编辑.bowerrc文件
{ "proxy": "http://proxy_ip_or_fqdn:8080", "https-proxy": "http://proxy_ip_or_fqdn:8080"
}
Ruby Gem代理设置&已经变更Gem源
Ruby Gem的代理设置和命令行CMD代理设置的方法一样。
但是,默认的 rubygems.org的源被墙掉了,因此需要变更默认的gem源,此外国内的淘宝镜像"ruby.taobao.org"也停止维护了,现在需要使用ruby-china提供的镜像服务(传送门)。
更改Gem源方法:
查看当前源
# gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
移除rubygems的源
# gem sources --remove https://rubygems.org/
增加ruby-china源
# gem sources --add https://gems.ruby-china.org/
确保只有gems.ruby-china.org源
# gem sources -l
更新缓存
# gem sources -u
如果遇到 SSL 证书问题,你又无法解决,请直接用 http://gems.ruby-china.org
替换https://gems.ruby-china.org
避免 SSL 的问题。