For terminal

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

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

For gradle and java

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

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