Skip to content
Back to blog

How to Set Up a Proxy on Ubuntu (GUI, Terminal & APT)

Table of contents

Key takeaways

  • A proxy that works in Chrome might not work in your terminal because they don’t always use the same proxy settings.
  • Temporary terminal proxy settings disappear when you close the session, but you can make them persistent using .bashrc.
  • Don't assume your proxy is working just because you've saved the settings. Compare your public IP address with and without it.

There are three main proxy configuration methods on Ubuntu. You can use your computer's network settings for compatible desktop applications, the terminal for individual commands and command-line tools, or APT to download software through a proxy server.

You'll need your proxy details from your provider's dashboard. So which method should you choose, and how do you configure it on Ubuntu? Let's find out.

How to configure a proxy on Ubuntu desktop (GUI)

Use Ubuntu's network settings to configure a proxy at the desktop level so compatible apps like Chrome can route traffic through it. Go about it this way when you want multiple desktop applications to use the same proxy configuration without setting up each one separately.

Set up an HTTP or HTTPS proxy

1. First, you'll need your proxy credentials. For this example, we're using MarsProxies Residential Proxies. Go to your MarsProxies dashboard and configure your proxy by selecting your country, state or region, rotation, and session duration (1). Under 'Type' (2), make sure to select 'HTTP'. See our residential proxy guide for more details on how to use the dashboard.

IMG1.webp

2. MarsProxies will now generate a proxy string with the proxy host, port, username, and password in the following format:

hostname:port:username:password

3. On your Ubuntu device, open 'Settings' from the application menu, then select 'Network' (3) from the left sidebar. Click the 'Proxy' (4) tab to open it.

IMG2.webp

4. Toggle the 'Network Proxy' (5) button to turn on Ubuntu's proxy settings.

IMG3.webp

5. Under 'Configuration', open the drop-down list and select 'Manual' (6).

IMG4.webp

6. The manual proxy configuration options will appear. Click the edit icon (7) in the 'HTTP Proxy' tab, then enter the hostname and port number (8) from your MarsProxies dashboard. Do the same for the 'HTTPS Proxy' (9) tab.

IMG5.webp

7. Click 'Save' at the top right corner of your screen. Whenever an app like Chrome wants to connect to the internet, it will prompt you to enter your username and password.

IMG6.webp

8. Go to your MarsProxies dashboard, copy your proxy username and password, paste them into the corresponding fields (10), and click 'Sign in' (11).

IMG7.webp

Configure a SOCKS5 proxy using network settings

To configure a SOCKS5 proxy using your Ubuntu network settings, you first need to generate your SOCKS5 proxy details in the MarsProxies dashboard.

1. Go to the MarsProxies dashboard and select the country, state/region, rotation, and session duration (1). Make sure to select 'SOCKS5' (2) under 'Type'.

IMG8.webp

2. MarsProxies will generate the proxy string in the following format:

hostname:port:username:password

3. Open 'Settings' from the application menu, then select 'Network' (3) from the left sidebar. Click 'Proxy' (4) to open the proxy settings.

IMG9.webp

5. Toggle 'Network Proxy' (5) to open the settings, then select 'Manual' (6) under 'Configuration'.

IMG10.webp

6. Scroll down until you see 'SOCKS Host', and click the edit icon (7). Enter your proxy host and port (8) from the MarsProxies dashboard.

IMG11.webp

7. Click 'Save' to apply your SOCKS5 proxy configuration, then open the app that you want to use SOCKS5 proxies with. A prompt will appear asking you to enter your username and password. Copy these proxy details from your MarsProxies dashboard, paste them into the corresponding fields, and click 'Sign in'.

If you’re unsure whether to use HTTP or SOCKS5, our SOCKS5 vs HTTP proxy comparison explains the differences and which protocol works best for different applications.

Set Up a Working Proxy on Ubuntu in 2026

Get proxies

How to set up a proxy in Ubuntu terminal

Setting up a proxy connection in your Ubuntu terminal gives you more control over how traffic gets routed. You can set up a temporary configuration to use when testing scripts in the command line, or a permanent one that routes all traffic from your terminal.

Configure a temporary proxy

1. Press Ctrl + Alt + T to open your terminal.

2. Enter the following command to check your current IP address. We’ll compare it with the proxy IP later:

curl --noproxy '*' https://api.ipify.org

Note the displayed IP address.

3. Go to your MarsProxies dashboard and configure your proxy’s country, state/region, rotation, and duration (1). Select 'HTTP' (2) under 'Type'.

IMG12.webp

4. To set a temporary HTTP/HTTPS proxy, use the following environment variables:

export http_proxy="http://HOST:PORT"
export https_proxy="http://HOST:PORT"

Replace HOST and PORT with the hostname and port from your MarsProxies dashboard.

5. Copy the following commands into your terminal. Bash will prompt you for your proxy username and password, which you can get from your MarsProxies dashboard.

read -r -p "Proxy username: " PROXY_USER
read -r -s -p "Proxy password: " PROXY_PASS
echo

6. Add the credentials to your proxy settings using the commands below. Doing so will tell compatible command-line applications which proxy server to use and how to authenticate:

export http_proxy="http://${PROXY_USER}:${PROXY_PASS}@${PROXY_HOST}:${PROXY_PORT}"
export https_proxy="$http_proxy"

Bash will automatically use the username and password you entered in step five.

7. Test the proxy IP using this command:

curl https://api.ipify.org

You should now see the proxy’s IP address.

This method creates a temporary proxy configuration that lasts for your current shell session. If you want requests to a specific server to use your regular connection while other requests use the proxy, use the no_proxy environment variable.

export no_proxy="localhost,127.0.0.1"

This command excludes requests to your own computer from the current proxy configuration.

Make proxy settings permanent

To make your proxy settings permanent, store your MarsProxies configuration in a file that .bashrc loads. That way, each new Ubuntu terminal session will read this file and apply the proxy settings to compatible applications.

1. Open the terminal and run:

cp -i ~/.bashrc ~/.bashrc.backup

Doing this backs up your current .bashrc file. Just a safety precaution in case it contains important shell settings.

2. Run the following commands to create a file for your proxy settings:

mkdir -p ~/.config/marsproxies
chmod 700 ~/.config/marsproxies
touch ~/.config/marsproxies/proxy.env
chmod 600 ~/.config/marsproxies/proxy.env

3. Open the file that you just created using the following command:

nano ~/.config/marsproxies/proxy.env

4. Then add this code:

export http_proxy='http://USERNAME:PASSWORD@HOST:PORT'
export https_proxy="$http_proxy"
export no_proxy="localhost,127.0.0.1,::1"

Replace USERNAME, PASSWORD, HOST, and PORT with the corresponding details from your MarsProxies dashboard. Save the file using Ctrl + O, press Enter, and exit using Ctrl + X.

5. Run the following command to open your .bashrc file:

nano ~/.bashrc

6. Scroll to the bottom of the file and add:

# Load MarsProxies settings
if [ -f "$HOME/.config/marsproxies/proxy.env" ]; then
    source "$HOME/.config/marsproxies/proxy.env"
fi

This tells Bash to load the proxy settings every time you open a new terminal session. Save it using Ctrl + O, press Enter, and exit using Ctrl + X.

7. Now run the following command to load your changes:

source ~/.bashrc

8. To confirm that the settings are working, close the current session and open a new one, then run the following command:

curl https://api.ipify.org

You should now see the IP address of the proxy that you just configured.

Set a system-wide proxy

Suppose you want applications beyond those in the terminal to use a proxy server. You can define a system-wide proxy configuration as environment variables inside /etc/environment.

Ubuntu reads these settings when you log in and makes them available to applications that you start during these sessions. However, only compatible applications will use the proxy.

Here is how to do it:

1. Back up your existing environment file using the following command:

sudo cp -i /etc/environment /etc/environment.backup

2. To open /etc/environment, run:

sudo nano /etc/environment

3. Without deleting the existing settings, add these lines:

http_proxy="http://USERNAME:PASSWORD@HOST:PORT"
https_proxy="http://USERNAME:PASSWORD@HOST:PORT"
no_proxy="localhost,127.0.0.1,::1"

Replace USERNAME, PASSWORD, HOST, and PORT with your MarsProxies details.

Here is what each of those lines means:

  • http_proxy tells compatible applications which proxy to use for HTTP requests
  • https_proxy provides the proxy address for HTTPS requests
  • no_proxy identifies destinations that should bypass the proxy

Press Ctrl + O, then Enter to save, and Ctrl + X to exit and return to the terminal.

For your applications to receive the new proxy settings, you need to log out and back in.

Configure a SOCKS5 proxy using cURL

If your workflow requires SOCKS5 support, you need to confirm that your provider supports SOCKS5 proxies before configuring one. For this example, we’ll test MarsProxies SOCKS5 proxies. Here’s how to go about it.

1. Go to your MarsProxies dashboard and configure your proxies. Select your country, state/region, rotation, and duration (1), then choose 'SOCKS5' (2) under 'Type'.

IMG13.webp

2. Press Ctrl + Alt + T to open your terminal. Then enter this cURL proxy command to check the SOCKS5 proxy:

curl --proxy "socks5h://SOCKS_HOST:SOCKS_PORT" \
  --proxy-user "USERNAME:PASSWORD" \
  https://api.ipify.org

Replace SOCKS_HOST, SOCKS_PORT, USERNAME, and PASSWORD with the corresponding details from your MarsProxies dashboard. If the connection succeeds, your terminal should display the public IP address of your SOCKS5 proxy.

How to configure an APT proxy on Ubuntu

If you’d like Ubuntu’s package manager to download software through a proxy server instead of connecting directly, you can create a dedicated APT proxy configuration file. APT reads this file whenever it starts.

Add proxy settings to APT

Here is how you can do it:

1. Go to your MarsProxies dashboard and configure your country, state/region, rotation options, and session duration (1), then choose ‘HTTP’ (2) under ‘Type’.

IMG14.webp

2. Press Ctrl + Alt + T to open the terminal and enter the following commands to create and open an APT configuration file:

sudo touch /etc/apt/apt.conf.d/95marsproxies-proxy
sudo chmod 600 /etc/apt/apt.conf.d/95marsproxies-proxy
sudo nano /etc/apt/apt.conf.d/95marsproxies-proxy

3. Inside the APT configuration file that opens in your terminal, enter the following lines:

Acquire::http::Proxy "http://USERNAME:PASSWORD@HOST:PORT/";
Acquire::https::Proxy "http://USERNAME:PASSWORD@HOST:PORT/";

4. Copy the hostname, port, username, and password from your MarsProxies dashboard, and paste them into the corresponding fields inside the APT configuration file. Once done, press Ctrl + O, then Enter to save, and Ctrl + X to exit.

Test your APT proxy configuration

Run:

sudo apt update

If APT successfully downloads package information through the proxy, your settings are working as intended.

How to check if your Ubuntu proxy is working

To confirm that your proxy configuration is working correctly, check your current proxy settings and verify whether your requests are going through the proxy server.

Check current proxy settings

The first step is to confirm that Ubuntu has retained or reloaded your proxy settings. How you do this depends on how you originally configured the proxy.

Start with the environment variables. Open your terminal and enter the following commands:

printenv http_proxy
printenv https_proxy

printenv will display the values of the environment variables. Expect to see the proxy details you configured, including credentials if you added them to the URLs. If you configured the proxy using Ubuntu’s network settings, go to ‘Settings’, open the ‘Proxy’ tab, and confirm the hostname and port you entered.

Verify your IP address using cURL

You can also use cURL to compare your public IP address with and without the proxy.

1. Check your IP without the proxy

Open your terminal and run:

curl --noproxy '*' https://api.ipify.org

The --noproxy '*' option tells cURL to bypass its configured proxies. Note the IP address returned, as you’ll use it for comparison. Our article on how to find your proxy server goes into more detail on how you can find the proxy configured on your Ubuntu device.

2. Check your IP through the proxy

Next, run:

curl https://api.ipify.org

If you configured the https_proxy environment variable earlier and it's still active, cURL will automatically route the request through that proxy.

3. Compare the results

If the second command returns a different IP address consistent with your selected proxy, that’s a good indication your connection is working.

Want to check more than your proxy's IP address? Our proxy testing guide covers how to verify proxy location, speed, and reliability.

For more information on proxy error codes, see our article on common proxy error codes to understand what different errors mean and how to resolve them.

How to disable or remove proxy settings on Ubuntu

The right way to disable or remove proxy settings depends on the proxy configuration method you used.

1. Disable the proxy through Ubuntu's GUI

  • Open ‘Settings’, click on ‘Network’, and then open the ‘Proxy’ tab
  • Turn ‘Network Proxy’ off
  • Save the changes

2. Remove temporary terminal proxy settings

Run this command:

unset http_proxy https_proxy no_proxy

3. Remove permanent proxy settings

With your terminal open, run the following command to open the Bash configuration file:

nano ~/.bashrc

Find and remove the lines you added earlier to load the proxy.env file, then save the file. Open a new terminal for the changes to take effect.

4. Remove the system-wide proxy

Run the following command to open /etc/environment:

sudo nano /etc/environment

Remove only the proxy settings you added and preserve the other system settings. Save the file, then log out and back in so new login sessions load the updated environment.

5. Remove APT proxy settings

Open your Ubuntu terminal and run:

sudo rm /etc/apt/apt.conf.d/95marsproxies-proxy

Doing so will remove the file we created earlier. Now verify that APT works without the proxy:

sudo apt update

If APT manages to access its repositories without the proxy, the removal worked.

Conclusion

The right way to set up a proxy on Ubuntu depends on where you want to use it.

Use Ubuntu's network settings when you want to configure proxies for compatible desktop applications. Terminal environment variables work best for supported command-line tools, while the APT method is best when you want Ubuntu's package manager to download software through a proxy.

Want more tips on setting up proxies on Ubuntu and other operating systems? Join our Discord channel.

FAQ

Can I use a proxy for only one application on Ubuntu?

Yes, you can configure a proxy directly in an application that supports its own proxy settings. For instance, Firefox allows manual proxy configuration, while cURL lets you route individual requests through a proxy using the --proxy option.

How do I configure a proxy with a username and password on Ubuntu?

You can include your authentication credentials in the proxy URL using the format http://USERNAME:PASSWORD@HOST:PORT for compatible applications. In the terminal, you can use this format with the http_proxy and https_proxy environment variables.

Why does my proxy work in the browser but not in the terminal?

Your browser could be using Ubuntu's desktop proxy settings. These settings don't automatically apply to command-line applications. To fix this, configure the http_proxy and https_proxy environment variables or specify the proxy directly in commands such as cURL. Also check that your authentication credentials are correct.

Does using a proxy on Ubuntu encrypt internet traffic?

Not necessarily. HTTP and SOCKS5 proxies don't provide encryption between your device and the proxy server by themselves. HTTPS websites still encrypt their connections using TLS, while an HTTPS proxy can additionally encrypt the connection between your device and the proxy.

Learn more

Related articles