For terminal

export http_proxy="socks5://127.0.0.1:1080"
export https_proxy="socks5://127.0.0.1:1080"

What if socks proxy is not supported?

Use polipo to turn a socks proxy into http proxy.

Install polipo

apt-get install polipo
service polipo start
polipo socksParentProxy=localhost:1080 &

If that went well, your http proxy is up. Now have a try with

http_proxy=http://localhost:8123 curl www.google.com

For gradle and java

Modify ~/.gradle/gradle.properties file. (This is the global per user config location. There's another one in android project folder.)

org.gradle.jvmargs=-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=6444