Gleb Lepeshkin Gleb Lepeshkin
Head of Content Marketing

On macOS you set a system proxy from the terminal with the networksetup command, and a per-shell proxy with the http_proxy and https_proxy environment variables. Use networksetup -setwebproxy “Wi-Fi” host port for HTTP and -setsecurewebproxy for HTTPS.

 

macOS Proxy Settings: GUI vs Command Line

For a one-time change through the interface, go to System Settings → Network → select your connection → Details → Proxies, check the protocol you need, and enter the host and port. This is the standard route for most users.

For scripting, automation, or remote administration over SSH, the command line is faster and does not require a display. macOS exposes two layers: networksetup for system-wide proxy settings that GUI apps obey, and shell environment variables for terminal-only tools in the current session.

 

Changing macOS Proxy Settings from the Command Line with networksetup

First, get the exact name of your network service:

networksetup -listallnetworkservices

The output usually shows Wi-Fi and Ethernet as separate entries. Use that exact label in every command that follows.

Set the HTTP proxy:

networksetup -setwebproxy “Wi-Fi” 1.2.3.4 8080

Set the HTTPS proxy:

networksetup -setsecurewebproxy “Wi-Fi” 1.2.3.4 8080

Set a SOCKS proxy:

networksetup -setsocksfirewallproxy “Wi-Fi” 1.2.3.4 1080

Turn the HTTP proxy off:

networksetup -setwebproxystate “Wi-Fi” off

If the proxy requires authentication, append the username and password as extra arguments:

networksetup -setwebproxy “Wi-Fi” 1.2.3.4 8080 on username password

To verify what is currently set on a service:

networksetup -getwebproxy “Wi-Fi”

 

Per-Shell Proxy with Environment Variables

networksetup changes the system proxy for all GUI apps. If you only need to route command-line tools like curl, git, or package managers in the current terminal session, use environment variables instead:

export http_proxy=”http://user:pass@host:port”

export https_proxy=”$http_proxy”

export no_proxy=”localhost,127.0.0.1″

To check what is currently active in the shell:

env | grep -i proxy

These variables disappear when you close the terminal window. That makes them useful for one-off tasks without touching the system configuration. To make them permanent, add the export lines to your ~/.zshrc or ~/.bash_profile.

To unset them in the current session:

unset http_proxy https_proxy

Rate this article, if you like it:

Ready to Proceed