When developing applications, it is common to interact with various tools that require a network connection to function correctly. However, many corporate networks use proxies to control access to the internet, which can cause these tools to fail if not configured correctly. In this article, we will look at how to set up and unset proxies for common tools like Yarn, NPM, Git, NVM, Yum, and Apt.
Proxy Setup in Linux
Most Linux distributions rely on either Yum or Apt as their package managers. To configure proxy settings for Yum and Apt-based systems, open your terminal and run the following commands:
YUM
Create a file called '/etc/yum.conf.proxy', which will hold your proxy configuration data:touch /etc/yum.conf.proxy && chmod 777 /etc/yum.conf.proxy
Edit the newly created file by opening it using a text editor such as 'nano' and adding the following configuration data:proxy=http://[username:password@]proxy-server-hostname:[port]/
Replace the bracketed terms with your proxy server's details, including your username and password (if applicable) followed by the proxy server hostname and port.
Export the HTTP_PROXY and HTTPS_PROXY environment variables so that all processes have access to the proxy settings stored in the /etc/yum.conf.proxy file, by running the following commands:
export http_proxy="http://[username:password@]proxy-server-hostname:[port]/"
export https_proxy="http://[username:password@]proxy-server-hostname:[port]/"
APT
Edit your '/etc/apt/apt.conf.d/proxy.conf' file using a text editor such as 'nano' and add the following lines of configuration data:
Acquire::http::Proxy "http://[username:password@]proxy-server-hostname:[port]/";
Acquire::https::Proxy "http://[username:password@]proxy-server-hostname:[port]/";
Replace the bracketed terms with your proxy server details, including your username and password (if applicable), followed by the proxy-server hostname and port.
Set up the HTTP_PROXY and HTTPS_PROXY environment variables so that all applications have access to the proxy settings stored in the '/etc/apt/apt.conf.d/proxy.conf' file, by running the following commands:
export http_proxy="http://[username:password@]proxy-server-hostname:[port]/"
export https_proxy="http://[username:password@]proxy-server-hostname:[port]/"
Proxy Setup in macOS
Many developers prefer Macs for coding because the macOS provides better support and flexibility for development. macOS utilizes bash shell, so you must configure proxy settings found in the bash profile file.
Open Terminal application and edit the '.bash_profile' file by running:
nano ~/.bash_profile
Add the following entries to the file:
export http_proxy="http://[username:password@]proxy-server-hostname:[port]/"
export https_proxy="http://[username:password@]proxy-server-hostname:[port]/"
Replace the bracketed terms with your proxy server details, including your username and password (if applicable), followed by the proxy-server hostname and port.
Save the changes made in the '.bash_profile' file and then run the following command to load the new configuration values:
source ~/.bash_profile
Proxy Setup in Windows
Windows users have several ways to configure proxy settings. In most cases, it is essential to adjust the settings for each of the applications individually.
NVM
If you utilize NVM (Node Version Manager) for Windows, modify the registry key named 'HTTP_PROXY' and 'HTTPS_PROXY.'
Launch cmd and navigate through this path
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
Right-click Internet Settings, select New -> String Value to create two new string values named HTTP_PROXY and HTTPS_PROXY that correspond to the respective environment variables.
Modify the value of HTTP_PROXY/HTTPS_PROXY appropriately, For example,
"http://<proxy>:<port>"
Git
If you’re using Git for Windows, there is an easy way to configure your proxy settings globally.
Open the Git Bash application.
Use the following commands to set up your global Git proxy configuration:
git config --global http.proxy [username:password@]your-proxy-server.com:[port]
git config --global https.proxy [username:password@]your-proxy-server.com:[port]
Replace the bracketed terms with your proxy server details, including your username and password (if applicable), followed by the proxy-server hostname and port.
Yarn and NPM
Yarn and NPM are straightforward as they inherit the environment variable configurations from the operating system's default environment variables.
Configure the proxy value by running the following command:npm config set proxy http://[username:password@]proxy-server-hostname:[port]/
yarn config set proxy http://[username:password@]proxy-server-hostname:[port]/
Replace the bracketed terms with your proxy server details, including your username and password (if applicable), followed by the proxy-server hostname and port.
Unconfigure by running the same command but with the word “delete” suffix:
npm config delete proxy
yarn config delete proxy
Conclusion
Proxy configurations remain critical to ensuring that tools frequently used by software developers work reliably across any network environment. As we have seen above, configuring proxies for tools like Yarn, NPM, Git, NVM, Yum, and Apt is relatively straightforward once you know what to do.