2021年2月28日 星期日

[經驗分享] 處理 apt upgrade 時發生找不到內容錯誤



在 Debian 與 Ubuntu 等 apt 軟體套件管理器的體系中,只要使用 apt update 與 upgrade 就可以輕鬆的升級相關軟體。

不過,最近在客戶環境中發現 apt update 與 upgrade 發生錯誤無法升級,確認網路完全沒有問題,這該怎麼處理呢?





問題狀況

我首先是執行 apt upgrade,想要升級這台伺服器上的套件,但出現了這個錯誤:

apt upgrade 發生錯誤


看到圖中的錯誤,有寫到 404 Not found [IP: 140.110.240.80 80],讓我第一時間想到的是網路問題,例如防火牆政策阻擋,或是 DNS 名稱解析有問題所致。

但經過查看網路相關狀況,都完全確認網路這端沒有任何問題。因此,我試著再做 apt update,想著 update 完應該就可以正確下載安裝了吧?

apt update 發生錯誤


哎呀,還是遇到問題,但這次的訊息比較明確了,寫著 The repository is not updated and the previos index file will be ubuntu.com/ubuntu.com/ubuntu bionic InRelease: Couldn't create temprary file /tmp/apt.confQc7I7f for passing config to apt-key 之類的內容,清楚多了。 










解決問題

既然知道跟 /tmp/apt.conf.xxxxxx 暫存檔有關,就用它來搜尋一些資料後確認,是暫存目錄的權限有問題造成,參考以下指令進行操作:
# 查看資料夾權限,正確結果應是 drwxrwxrwt
ls -lad /tmp

# 若權限不正確,請修正它
chmod 1777 /tmp

# 保險一點,建議重新啟動
reboot

重新啟動完成後,已經可以正常 apt update 與 upgrade,問題解決!







參考資料