Setting proxy for ArchLinux.

Sometimes when you are behind corporate or university network you might
need to setup HTTP/HTTPS proxy settings to access the Internet. Setting up proxy on linux is simple enough, you just need to export environment variables , you can add to your shell configuration file.

1
2
export http_proxy=http://<ip>:<port>
export https_proxy=$http_proxy

But when you’ll try to run your package manager with sudo , these variables will not be passed onto root. This becomes particularly annoying when you have to use AUR repository and it would not build packages in root and when you try to run it with unprivileged user, it fails to download dependencies via pacman. There are two methods to fix this.

1) Pass on environment variables to root

  • Run to following command to edit sudoers file

    1
    $ sudo visudo
  • add the following line

    1
    Defaults env_keep += "https_proxy http_proxy"

this way $https_proxy and $http_proxy will be passed onto root by sudo.
Also make sure you have set environment variables for current user. If
not then you can add it by editing .bashrc if you use bash or
~/.config/fish/config.fish if you use fish like me.

1
2
export http_proxy=http://<ip>:<port>
export https_proxy=$http_proxy

2) Set proxy for pacman

You also directly set proxy for pacman by editing /etc/pacman.conf

  • open pacman config file by
    1
    $ sudo nano nano /etc/pacman.conf

uncomment XferCommand so that it looks like

1
XferCommand = /usr/bin/wget --passive-ftp --proxy=on -c -O %o %u

save it and then open /etc/wgetrc

and uncommand the following lines so that it looks like

1
2
3
https_proxy = http://<ip>:<port>
http_proxy = http://<ip>:<port>
use_proxy = on

This should make pacman run via sudo.

For other applications like firefox you can set proxy directly through

Preferences > Advanced > Network > Settings

and for chrome / chromium you’d need to pass argument to use proxy like

1
~$ chromium --http-proxy=<ip>:<port>

Most of the things which need internet and work over http/https proxy should work now.