Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux yum 被鎖定無法執行?三步快速解除鎖定恢復正常

編輯:Linux 系統常見問題解答

執行 yum install 時遇到 Existing lock /var/run/yum.pid: another copy is running as pid XXXX 錯誤,通常是系統自動更新服務正在佔用 yum 鎖。本文提供三步標準解決流程,並說明原理與替代方案。

錯誤現象

# yum -y install vixie-cron
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 25960.
Another app is currently holding the yum lock; waiting for it to exit...

標準三步解決流程

步驟 1:嘗試正常終止佔用進程

# 先查看進程詳情
ps aux | grep yum

# 嘗試優雅終止 (SIGTERM)
kill 25960

# 若無效,強制終止 (SIGKILL)
kill -9 25960

注意:若進程狀態為 Z (殭屍進程),kill 無效需進行步驟 2。

步驟 2:強制移除鎖定檔案

rm -f /var/run/yum.pid

此為最直接有效的方法,移除鎖定檔後 yum 即可正常運作。

步驟 3:重啟 yum 更新服務 (防止殘留服務再次鎖定)

# CentOS 6 / RHEL 6
/sbin/service yum-updatesd restart

# CentOS 7 / RHEL 7 / Fedora (systemd)
systemctl restart yum-updatesd.service
# 或
systemctl restart dnf-makecache.timer

完整實戰案例回顧

# 1. 發現鎖定
yum -y install gcc* ...

# 2. 查看進程
ps -ef | grep update
# 發現 python /usr/sbin/yum-updatesd

# 3. kill 進程 (可能無效)
kill -9 PID

# 4. 強制刪除鎖定檔
rm -f /var/run/yum.pid

# 5. 重啟更新服務
/sbin/service yum-updatesd restart

# 6. 再次執行 yum 即正常
yum -y install gcc* ...

預防與替代建議

  • 若頻繁遇到,考慮停用自動更新服務:systemctl disable yum-updatesd (手動定期更新)
  • 使用 yum --nolock 參數可暫時忽略鎖定 (不建議常態使用)
  • 排程更新建議設在低峰時段 (如凌晨 3-4 點) 避免衝突
Copyright © Windows教程網 All Rights Reserved