This error occurs when the apt proxy configuration file contains syntax errors, most commonly missing semicolons at the end of configuration lines. APT parses all files in /etc/apt/apt.conf.d/ strictly, so any malformed syntax will prevent package updates.
The "E: Syntax error in apt.conf.d/proxy.conf" error indicates that APT's configuration parser encountered invalid syntax in your proxy configuration file. APT is strict about configuration syntax and requires precise formatting according to its grammar rules. This error typically manifests when: - **Missing semicolons**: Configuration lines in proxy.conf must end with a semicolon. APT treats this as required punctuation, not optional. - **Incorrect proxy syntax format**: Using the wrong syntax pattern for proxy declarations. APT supports specific formats like `Acquire::http::Proxy "..."` or `Acquire { http::Proxy "..."; }`. - **Malformed proxy URLs**: Proxy URLs with spaces, unescaped special characters, or invalid format can cause parsing failures. - **Extra characters or junk at end of file**: Trailing whitespace, extra blank lines, or characters after the closing semicolon can confuse the parser. - **Mixed syntax formats**: Mixing different proxy declaration styles in the same file without proper syntax structure. The error message typically shows the exact line where parsing failed, making it easier to locate the problematic configuration.
First, examine the proxy.conf file to see its current contents:
cat /etc/apt/apt.conf.d/proxy.confThe error message usually indicates the line number with the problem. Look for:
- Lines missing semicolons at the end
- Mismatched quotes in proxy URLs
- Extra characters or incomplete syntax
APT requires strict syntax with semicolons at the end of each line. The correct format is:
For simple proxy (HTTP/HTTPS):
sudo nano /etc/apt/apt.conf.d/proxy.confEnter this content (note the semicolon at the end):
Acquire::http::Proxy "http://proxy-server:8080";
Acquire::https::Proxy "http://proxy-server:8080";
Acquire::ftp::Proxy "ftp://proxy-server:8080";Save with Ctrl+O, Enter, Ctrl+X.
For proxy with authentication:
Acquire::http::Proxy "http://username:password@proxy-server:8080";
Acquire::https::Proxy "http://username:password@proxy-server:8080";Important: Each line MUST end with a semicolon. Missing semicolons are the most common cause of this error.
After editing, test if apt can parse the configuration:
sudo apt updateIf you still get the syntax error, the file still has issues. If it succeeds, the syntax is correct.
Check for common mistakes in your file:
# View the exact file contents with line numbers
cat -n /etc/apt/apt.conf.d/proxy.confLook for:
- Lines without semicolons at the end
- Extra spaces or characters after the closing semicolon
- Incomplete or malformed proxy URLs
If your proxy username or password contains special characters, they must be URL-encoded:
Characters that need encoding:
- @ → %40
- : → %3A
- / → %2F
- # → %23
- ? → %3F
- = → %3D
- Space → %20
Example with special characters:
# Original credentials: user@domain:P@ssw0rd
# URL-encoded: user%40domain:P%40ssw0rd
echo 'Acquire::http::Proxy "http://user%40domain:P%40ssw0rd@proxy-server:8080";' | sudo tee /etc/apt/apt.conf.d/proxy.confYou can use Python to encode:
python3 -c "from urllib.parse import quote; print(quote('P@ssw0rd', safe=''))"If line-by-line syntax is giving issues, try the block format instead:
sudo tee /etc/apt/apt.conf.d/proxy.conf << EOF
Acquire {
HTTP::Proxy "http://proxy-server:8080";
HTTPS::Proxy "http://proxy-server:8080";
FTP::Proxy "ftp://proxy-server:8080";
};
EOFKey points for block syntax:
- Opening brace: {
- Each line inside must end with semicolon
- Closing brace must be followed by semicolon: };
- No semicolon after individual proxy lines in some contexts
Then test:
sudo apt updateSometimes the file contains invisible characters or wrong line endings that cause syntax errors:
# View hidden characters
cat -A /etc/apt/apt.conf.d/proxy.confLook for:
- ^M at the end of lines (Windows line endings) - should be $ only
- Extra spaces or tabs
- Strange characters
Convert DOS line endings to Unix:
sudo dos2unix /etc/apt/apt.conf.d/proxy.confOr using sed:
sudo sed -i 's/\r$//' /etc/apt/apt.conf.d/proxy.confRecreate the file from scratch:
If the file is corrupted, delete and recreate it:
sudo rm /etc/apt/apt.conf.d/proxy.conf
echo 'Acquire::http::Proxy "http://proxy-server:8080";' | sudo tee /etc/apt/apt.conf.d/proxy.conf
sudo apt updateAPT provides a way to check configuration syntax before running update:
# Check for syntax errors in all config files
apt-config shell | headOr dump the entire parsed configuration:
apt-config dump | grep -i proxyIf this succeeds, your configuration is valid. If it fails with a syntax error, the problem is still in your files.
Check individual files:
# List all files in apt.conf.d
ls -la /etc/apt/apt.conf.d/
# Each file should be syntactically valid on its ownIf you cannot resolve the syntax issue, temporarily disable the proxy configuration:
# Rename the file to disable it
sudo mv /etc/apt/apt.conf.d/proxy.conf /etc/apt/apt.conf.d/proxy.conf.disabled
# Test if apt works without proxy
sudo apt updateThen either:
Option 1: Use environment variables instead:
# Set proxy environment variables
export http_proxy="http://proxy-server:8080"
export https_proxy="http://proxy-server:8080"
export ftp_proxy="ftp://proxy-server:8080"
sudo -E apt updateOption 2: Recreate the file with minimal syntax:
# Create a simple, clean proxy.conf
sudo tee /etc/apt/apt.conf.d/99proxy << 'EOF'
Acquire::http::Proxy "http://proxy-server:8080";
Acquire::https::Proxy "http://proxy-server:8080";
EOF
sudo apt updateOnce you confirm apt works, diagnose the original file to understand what went wrong.
Understanding APT configuration parsing:
APT uses a strict configuration parser that requires proper syntax. Unlike some configuration formats that are lenient, APT will completely reject malformed configuration and prevent all package operations.
APT configuration grammar:
- Identifiers: Acquire, http, https, ftp, Proxy, etc.
- Operators: :: (scope resolution) and { } (blocks)
- Values: Strings in quotes
- Terminators: Semicolons required at end of statements
When APT loads config files:
1. APT reads all files in /etc/apt/apt.conf.d/ in alphabetical order
2. Files are parsed sequentially
3. If ANY file has a syntax error, parsing stops and apt fails
4. The error message usually indicates the filename and line number
Filename conventions in apt.conf.d:
APT processes files in order, so naming matters:
- 50unattended-upgrades - Numbered prefixes control order
- 01proxy - Lower numbers processed first
- 99custom - Higher numbers processed last
Proxy configuration scope resolution:
- Acquire::http::Proxy - Only for HTTP connections
- Acquire::https::Proxy - Only for HTTPS (highly recommended)
- Acquire::ftp::Proxy - Only for FTP repositories
- Acquire::socks::Proxy - SOCKS proxy support
Port configuration:
Always include the port in the proxy URL, even if it's the default:
- http://proxy-server:8080 - Explicit port
- http://proxy-server - May fail if default port differs
Authentication in proxy URLs:
Format: scheme://username:password@host:port/
Special characters in passwords MUST be URL-encoded. Do not include the trailing slash in proxy.conf entries.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT