Proxy Config Handbook for Software Engineers

Setting up Bash, CMD, Git, Maven, Gradle, NPM, Bower, Yarn, APM, Ionic, Docker, Ruby Gem, Android SDK, IDEs, and Various Applications with Proxy Settings

During my internship, I got the privilege to work with so many R&D projects related to various technology stacks. Since it was hard for me to remember all those proxy configurations, I decided to document them all in one place. Check the following list of proxy configurations in my collection. If you face any issues or need settings for a tool which is not listed here, please let me know. Hope my efforts will make your life easy!


How to find a setting

  • Press CTRL + F
  • Type the tool you need

Prerequisites

First of all, obtain the following information from your network administrator.

1) Username
2) Password
3) Host
4) Port

With those, you can create a proxy string in the following format.

// With Authentication
http://username:password@host:port
// Without Authentication
http://host:port
// Examples
http://ashen:abc123@192.125.0.209:6780
http://student123:guest@10.10.10.72:8801
http://
192.125.0.209:6780
http://10.10.10.72:8801
NOTE: If you have special characters in your credentials, you will have to use unicode characters in hexadecimal. If you have spaces between words in the credentials, again you will have to wrap the entire string with “__”.

Look at the given Proxy Configuration window of IntelliJ IDEA. To setup proxy, you need to select Manual proxy configuration and type as HTTP. Fill in the Host name and Port number. If you have access credentials, enter them too. If you want your proxy to bypass any links such as localhost, add them to No proxy for box. Every software which provides a GUI to configure proxy needs you to follow the similar steps as I explained. But for some development tools (specially build tools and package managers), you don’t get a GUI. In such cases, you will have to use the terminal or a configuration file to setup proxy.


1) Linux Bash

Set Proxy

// With Authentication
export http_proxy='
http://username:password@host:port'
export https_proxy='
http://username:password@host:port'
export ftp_proxy='
http://username:password@host:port'
// Without Authentication
export http_proxy='
http://host:port'
export https_proxy='
http://host:port'
export ftp_proxy='
http://host:port'

If you prefer doing this manually, find .bash_profile or .bashrc file and update with the following lines.

export http_proxy=[Your Proxy]:[Proxy Port]
export https_proxy=[Your Proxy]:[Proxy Port]
export npm_config_proxy=[Your Proxy]:[Proxy Port]
export npm_config_https_proxy=[Your Proxy]:[Proxy Port]

Note: After updated the .bash_profile or .bashrc, you should run one of the following commands to make the configuration active for the current session.

source ~/.bashrc
// or
source ~/.bash_profile

View Proxy

env | grep -i proxy 

Remove Proxy

unset http_proxy
unset https_proxy
unset ftp_proxy

2) Windows Command Prompt

Set Proxy

Case 1: For Current Session;

// With Authentication
set http_proxy='http://username:password@host:port'
set https_proxy='
http://username:password@host:port'
// Without Authentication
set http_proxy='http://host:port'
set https_proxy='http://
host:port'

Case 2: To configure proxy globally as a System Environment Variable, run from an administrative command prompt:

// With Authentication
setx http_proxy='http://username:password@host:port' /M
setx https_proxy='http://username:password@host:port' /M
// Without Authentication
setx http_proxy='http://host:port' /M
setx https_proxy='
http://host:port' /M

You will need to close and re-open command prompt for settings to take effect.

Case 3: To configure proxy globally as a User Environment Variable, run from a non-administrative command prompt:

// With Authentication
setx http_proxy='http://username:password@host:port'
setx https_proxy='http://username:password@host:port'
// Without Authentication
setx http_proxy='http://host:port'
setx https_proxy='
http://host:port'

You will need to close and re-open command prompt for settings to take effect.

Remove Proxy

Case 1: For Current Session:

set http_proxy=''
set https_proxy=''

Case 2: For Global System Environment Variable, run from an administrative command prompt:

// With Authentication
setx http_proxy='' /M
setx https_proxy='' /M
// Without Authentication
setx http_proxy='' /M
setx https_proxy='' /M

You will need to close and re-open command prompt for settings to take effect.

Case 3: For Global User Environment Variable, run from an administrative command prompt:

// With Authentication
setx http_proxy=''
setx https_proxy=''
// Without Authentication
setx http_proxy=''
setx https_proxy=''

You will need to close and re-open command prompt for settings to take effect.

View Proxy

If the commands below just echo out the text instead of the actual proxy server, it means that the proxy server is not set.

echo %http_proxy%
echo %https_proxy%

3) Git

Set Proxy

// With Authentication
git config --add http.proxy "http://username:password@host:port"
git config --add https.proxy "
http://username:password@host:port"
// Without Authentication
git config --add http.proxy "http://host:port"
git config --add https.proxy "
http://host:port"

Alternatively, you can edit the ~/.gitconfig file in your system root directory.

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

View Proxy

git config --get http.proxy
git config --get https.proxy
// All Configurations
git config --list

Remove proxy

git config --unset http.proxy
git config --unset https.proxy

4) Maven

Edit the proxies section 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

5) Gradle

Add the below in your gradle.properties file and in your gradle/wrapper/gradle-wrapper.properties file if you are downloading the wrapper over a proxy

If you want to set these properties globally then add it in USER_HOME/.gradle/gradle.properties file

## Proxy setup
systemProp.proxySet="true"
systemProp.http.keepAlive="true"
systemProp.http.proxyHost=host
systemProp.http.proxyPort=port
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=local.net|some.host.com

systemProp.https.keepAlive="true"
systemProp.https.proxyHost=host
systemProp.https.proxyPort=port
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=pssword
systemProp.https.nonProxyHosts=local.net|some.host.com
## end of proxy setup

6) NPM

Set Proxy

// With Authentication
npm config set proxy "http://username:password@host:port"
npm config set http-proxy "http://username:password@host:port"
npm config set https-proxy "http://username:password@host:port"
// Without Authentication
npm config set proxy "http://host:port"
npm config set https-proxy
"http://host:port"

Alternatively, you can find the ~/.npmrc file in your system root directory and add following lines for configuring proxy.

With Authentication

// With Authentication
proxy="http://username:password@host:port"
http-proxy="
http://username:password@host:port"
https-proxy="
http://username:password@host:port"
// Without Authentication
proxy:"http://host:port"
http-proxy="
http://host:port"
https-proxy="
http://host:port"

View Proxy

You can run the below commands or view ~/.npmrc file.

npm config get https-proxy
npm config get proxy

Remove proxy

You can run the below commands or edit ~/.npmrcfile.

npm config delete https-proxy
npm config delete proxy
// or
npm config set https-proxy null
npm config set proxy null

7) Bower

There is no command line that I found for configuring bower. Instead you need to create a .bowerrc file in the users home directory.

On Windows: %userprofile% directory.

On Linux: ~/

On Linux, you can create this .bowerrc file easily. But Windows Explorer unfortunately does not allow you to create files without extensions. Let’s use notepad and create a file without an extension.

  1. Open Notepad
  2. Ctrl + S to save the file
  3. Navigate to the %UserProfile% directory
  4. Change the “Save as Type” to “All Files (.)
  5. Name the file .bowerrc
  6. Click the Save button
  7. Now you can edit the file in your text editor of choice

Now edit the ~/.bowerrc file with the following lines.

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

View Proxy

You can view the ~/.bowerrc file or use the following the command.

gedit .bowerrc

Remove proxy

Feel free to edit the proxy configuration lines in the ~/.bowerrc file.


8) Yarn

Set Proxy

// With Authentication
yarn config set proxy "http://username:password@host:port"
yarn config set https-proxy "
http://username:password@host:port"
// Without Authentication
yarn config set https-proxy "http://host:port"
yarn config set proxy "
http://host:port"

View Proxy

yarn config get https-proxy
yarn config get proxy

Remove proxy

yarn config delete https-proxy
yarn config delete proxy
// or
yarn config set https-proxy null
yarn config set proxy null

APM

Set Proxy

// With Authentication
apm config set proxy "http://username:password@host:port"
apm config set https-proxy "
http://username:password@host:port"
// Without Authentication
apm config set https-proxy "http://host:port"
apm config set proxy "
http://host:port"

View Proxy

apm config get https-proxy
apm config get proxy

Remove proxy

apm config delete https-proxy
apm config delete proxy

or

apm config set https-proxy null
apm config set proxy null

Ionic

Set Proxy

When you start the app, add the proxy configuration to your start command.

// Linux
//
With Authentication
PROXY="http://username:password@host:port" ionic start [your app]
//
Without Authentication
PROXY="http://host:port" ionic start [your app]
// Windows
// With Authentication
setx http_proxy "http://username:password@host:port" /M
ionic start [App Name]
//
Without Authentication
setx http_proxy "http://host:port" /M
ionic start [App Name]

Docker

Native Docker

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

Then, you have to restart the docker service with: sudo service docker restart.

It will not apply to systemd. See this page from docker to configure the 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.


Ruby Gem Install

If you have set the proxy in the .bash_profile or .bashrc, then Ruby should pick it up.

If you need to manually set it, use following commands.

// Linux
export http_proxy=proxy:port sudo gem install [your gem name]
// Windows
setx http_proxy "host:port" /M
gem install [your gem name]

Android SDK

The android SDK uses ~/.android/androidtool.cfg file to define the proxy information. If the file does not exist, go ahead and create it.

http.proxyHost=host
http.proxyPort=port