Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Proxy configuration by command line for some tools

Yarn configuration

$ yarn config set proxy http://username:password@host:port

$ yarn config set https-proxy http://username:password@host:port

NPM configuration

$ npm config set proxy http://username:password@host:port

$ npm config set https-proxy http://username:password@host:port

Or you can edit directly your ~/.npmrc file:

proxy=http://username:password@host:port

https-proxy=http://username:password@host:port

https_proxy=http://username:password@host:port

Remove configuration

npm config rm proxy

npm config rm https-proxy

Git configuration

git config --global http.proxy http://username:password@host:port

git config --global https.proxy http://username:password@host:port

Or you can edit directly your ~/.gitconfig file:

[http]
        proxy = http://username:password@host:port
[https]
        proxy = http://username:password@host:port

Bower configuration

Edit your ~/.bowerrc file:

{
    "proxy":"http://username:password@host:port",
    "https-proxy":"http://username:password@host:port"
}

Maven configuration

Edit the proxies session in your ~/.m2/settings.xml file

<proxies>
    <proxy>
        <id>id</id>
        <active>true</active>
        <protocol>http</protocol>
        <username>username</username>
        <password>password</password>
        <host>host</host>
        <port>port</port>
        <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
</proxies>

Maven Wrapper

Create a new file .mvn/jvm.config inside the project folder and set the properties accordingly:

-Dhttp.proxyHost=host 
-Dhttp.proxyPort=port 
-Dhttps.proxyHost=host 
-Dhttps.proxyPort=port 
-Dhttp.proxyUser=username 
-Dhttp.proxyPassword=password

Docker

Native Docker

Depending on your OS, you have to edit a specific file (/etc/sysconfig/docker or /etc/default/docker).

Then, restart the docker service with: sudo service docker restart.

It will not apply to systemd. See this page: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy

Docker with docker-machine

You can create your docker-machine with:

docker-machine create -d virtualbox \
    --engine-env HTTP_PROXY=http://username:password@host:port \
    --engine-env HTTPS_PROXY=http://username:password@host:port \
    default

Or you can edit the file ~/.docker/machine/machines/default/config.json.

Ubuntu

System-wide proxies in CLI Ubuntu/Server must be set as environment variables.

  1. Open the /etc/environment file with vi (or your favorite editor). This file stores the system-wide variables initialized upon boot.

Add the following lines, modifying appropriately. You must duplicate in both upper-case and lower-case because (unfortunately) some programs only look for one or the other:

http_proxy="http://myproxy.server.com:8080/"
https_proxy="http://myproxy.server.com:8080/"
ftp_proxy="http://myproxy.server.com:8080/"
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
HTTP_PROXY="http://myproxy.server.com:8080/"
HTTPS_PROXY="http://myproxy.server.com:8080/"
FTP_PROXY="http://myproxy.server.com:8080/"
NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
  1. apt-get, aptitude, etc. will not obey the environment variables when used normally with sudo. So separately configure them; create a file called 95proxies in /etc/apt/apt.conf.d/, and include the following:
Acquire::http::proxy "http://myproxy.server.com:8080/";
Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
Acquire::https::proxy "https://myproxy.server.com:8080/";
  1. Verify that apt has picked up these settings via this command

apt-config dump | grep -i proxy # lists the proxy settings

Finally, logout and reboot to make sure the changes take effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment