You're right - apt doesn't natively support SOCKS proxies through environment variables. Here are the working solutions for SOCKS proxies with apt:
Method 1: Using proxychains (Recommended)
Install proxychains:
sudo apt install proxychains4
Configure proxychains by editing /etc/proxychains4.conf:
sudo nano /etc/proxychains4.conf
At the bottom of the file, replace the existing proxy line with your SOCKS proxy:
socks5 127.0.0.1 1080
or
socks4 proxy-server port
Then run apt commands through proxychains:
sudo proxychains4 apt update
sudo proxychains4 apt install package-name
Method 2: Using tsocks
Install tsocks:
sudo apt install tsocks
Configure /etc/tsocks.conf:
sudo nano /etc/tsocks.conf
Add:
server = your-socks-proxy-ip
server_port = your-socks-proxy-port
server_type = 5
Then use:
sudo tsocks apt update
Method 3: Local HTTP-to-SOCKS proxy
Install privoxy to convert SOCKS to HTTP proxy:
sudo apt install privoxy
Edit /etc/privoxy/config:
sudo nano /etc/privoxy/config
Add this line (replace with your SOCKS proxy details):
forward-socks5 / socks-proxy-ip:port .
Start privoxy:
sudo systemctl start privoxy
sudo systemctl enable privoxy
Then configure apt to use the local HTTP proxy:
sudo nano /etc/apt/apt.conf.d/95proxies
Add:
Acquire::http::Proxy "http://127.0.0.1:8118/";
Acquire::https::Proxy "http://127.0.0.1:8118/";
Proxychains is usually the simplest solution if you just need occasional use of apt through SOCKS proxy.