Setting the proxy environment variable in zsh is crucial when working in a network environment that requires routing traffic through a proxy server. This configuration ensures that network commands like curl, wget, and system package managers use the proxy server to access external resources.

In zsh, the proxy environment variables include HTTP_PROXY and HTTPS_PROXY. These variables direct HTTP and HTTPS traffic to the appropriate proxy server. You can also set the NO_PROXY variable to bypass the proxy for certain domains or IP addresses.

The steps below outline how to set these proxy variables for both temporary use in the current session and permanently through the .zshrc configuration file.

Steps to set proxy environment variable in zsh:

  1. Open the terminal.
  2. Temporarily set the HTTP and HTTPS proxy for the current session.
    $ export HTTP_PROXY=http://proxy.example.com:8080
    $ export HTTPS_PROXY=https://proxy.example.com:8080
  3. To make the proxy setting permanent, open the .zshrc file in a text editor.
    $ vim ~/.zshrc
  4. Add the following proxy settings to the .zshrc file.
    $ export HTTP_PROXY=http://proxy.example.com:8080
    $ export HTTPS_PROXY=https://proxy.example.com:8080
    $ export NO_PROXY=localhost,127.0.0.1

    Make sure to replace “proxy.example.com” and “8080” with the actual proxy details for your network.

  5. Save and exit the .zshrc file.
  6. Apply the changes to the current shell session.
    $ source ~/.zshrc
  7. Verify the proxy settings are applied by checking the environment variables.
    $ echo $HTTP_PROXY
    http://proxy.example.com:8080
    $ echo $HTTPS_PROXY
    https://proxy.example.com:8080
Discuss the article:

Comment anonymously. Login not required.