執行 sudo add-apt-repository ppa:... 時出現 Cannot add PPA: 'ppa:...'. Please check that the PPA name or format is correct.,主因通常為 本機 CA 憑證損壞 或 網路環境需經代理但 sudo 未傳遞代理變數。本文提供兩步驟修復方案。
sudo apt-get install --reinstall ca-certificates
# 完成後再次嘗試 add-apt-repository
原理:add-apt-repository 需驗證 Launchpad PPA 的 HTTPS 憑證,若 /etc/ssl/certs 中根憑證損壞/過期,驗證失敗導致無法新增。
# 假設代理為 https://proxy.example.com:8080
export http_proxy=https://proxy.example.com:8080
export https_proxy=https://proxy.example.com:8080
# 關鍵:使用 -E 參數保留環境變數
sudo -E add-apt-repository ppa:linrunner/tlp
sudo -E (或 --preserve-env) 會將當前 Shell 的環境變數 (含 http_proxy/https_proxy) 傳遞給 root 環境,使 add-apt-repository 能透過代理連線 Launchpad。
sudo apt-get update
# 若無錯誤且顯示 PPA 套件列表,即表示新增成功
date,時間偏差大會導致憑證驗證失敗。
gpg --keyserver keyserver.ubuntu.com --recv-keys
gpg --export | sudo apt-key add -
/etc/apt/sources.list.d/ 是否有殘留損壞的 .list 檔案,刪除後重試。