126

How can I set up "curl" to permanently use a proxy server in the terminal?

3
  • 38
    why was this question closed? seems quite important to me... Commented Jul 8, 2013 at 15:40
  • 1
    I suspect it was considered off topic because it did not explicitly mention how cURL was being used in a programming problem (e.g. writing a script to do something interesting). It might have just as well been formulated as a sysadmin question better suited to ServerFault. Commented Aug 10, 2015 at 20:56
  • 1
    stackoverflow.com/questions/9445489/… Commented Nov 14, 2016 at 8:42

4 Answers 4

206

You can make a alias in your ~/.bashrc file :

alias curl="curl -x <proxy_host>:<proxy_port>" 

Another solution is to use (maybe the better solution) the ~/.curlrc file (create it if it does not exist) :

proxy = <proxy_host>:<proxy_port> 
Sign up to request clarification or add additional context in comments.

5 Comments

Setting the proxy in ~/.curlrc has saved me many painful hours when working from within a corporate proxy. Thanks!
what about user:pass auth to that?
You could try the format username:password@proxy:port.
If anyone comes along and is trying to accomplish this with Windows / DOSKEY, I used alias curl=curl --proxy <proxy server:port> $*
Worked on Ubuntu 20 as well
52

Many UNIX programs respect the http_proxy environment variable, curl included. The format curl accepts is [protocol://]<host>[:port].

In your shell configuration:

export http_proxy http://proxy.server.com:3128 

For proxying HTTPS requests, set https_proxy as well.

Curl also allows you to set this in your .curlrc file (_curlrc on Windows), which you might consider more permanent:

http_proxy=http://proxy.server.com:3128 

3 Comments

env variable did not work for me (in Terminal on a mac).
To proxy HTTPS traffic on mac, setting the https_proxy env variable in the terminal before invoking curl, worked for me. For example, export https_proxy=https://proxy.server.com:6443
Also note that setting HTTP_PROXY/HTTPS_PROXY (uppercase) does not work, but setting http_proxy/https_proxy (lowercase) does.
19

Curl will look for a .curlrc file in your home folder when it starts. You can create (or edit) this file and add this line:

proxy = yourproxy.com:8080 

2 Comments

This works on Ubuntu 16.04. It should be accepted answer for that OS.
Can confirm it worked for Ubuntu 20 as well.
14

One notice. On Windows, place your _curlrc in '%APPDATA%' or '%USERPROFILE%\Application Data'.

1 Comment

Unfortunately, this did not work for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.