dpkg:不可恢复的致命错误(包“java-common”的文件列表文件缺少最后的换行符)

问题描述 投票:0回答:6

我正在尝试使用命令

apt-get install ...
在我的 Linux 操作系统上安装软件包。 问题是我收到此错误:

Selecting previously unselected package liberror-perl.
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'java-common' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

谷歌搜索错误(甚至逐行),解决方案似乎是“下载并安装缺少的软件包以解决依赖关系”,正如here所指出的那样。问题是,当我尝试执行

sudo apt-get -f install
时,我仍然一次又一次地遇到相同的错误。有什么建议吗?如果无法使用 apt-get 如何更改软件包?

linux ubuntu apt-get dpkg
6个回答
20
投票

我已经使用python脚本解决了这个问题:

#!/usr/bin/python


# 8th November, 2009
# update manager failed, giving me the error:
# 'files list file for package 'xxx' is missing final newline' for every package.
# some Googling revealed that this problem was due to corrupt files(s) in /var/lib/dpkg/info/
# looping though those files revealed that some did not have a final new line
# this script will resolve that problem by appending a newline to all files that are missing it
# NOTE: you will need to run this script as root, e.g. sudo python newline_fixer.py

import os

dpkg_path = '/var/lib/dpkg/info/'
paths = os.listdir(dpkg_path)
for path in paths:
    path = dpkg_path + path
    f = open(path, 'a+')
    data = f.read()
    if len(data) > 1 and data[-1:] != '\n':
        f.write('\n')
        print 'added newline character to:', path
    f.close() 

使用命令

sudo python name_script.py
运行脚本后,问题解决了:似乎某些文件已损坏。解决方案已在here

提出

5
投票

您必须删除丢失的文件

 sudo rm /var/lib/dpkg/info/java-common.list 

现在您可以重新安装这个

 sudo apt-get install java-common --reinstall 

0
投票

如果您遇到以下错误

dpkg:不可恢复的致命错误,正在中止: 包“java-common”的文件列表文件缺少最后的换行符 E: 子进程 /usr/bin/dpkg 返回错误代码 (2)

注意:java-common 是列表名称

使用以下命令解决此问题(使用您的列表名称修改 java-common)

sudo rm /var/lib/dpkg/info/java-common.list

sudo apt-get install java-common --reinstall

sudo dpkg --configure -a 须藤apt更新 sudo apt 升级


0
投票
  • sudo dpkg --configure -a
  • sudo apt-get -f 安装 sudo apt-get clean
  • sudo apt-get 更新 && sudo apt-get 升级

它解决了我的问题。


0
投票

我尝试了以下命令,它对我有用

$ sudo apt-get update
$ sudo apt update && sudo apt upgrade

0
投票

对于在

python3
上尝试此操作并收到此错误的任何人:

Traceback (most recent call last):
  File "/home/atharva/Documents/development/fix_updates.py", line 20, in <module>
    f.seek(-1, os.SEEK_END)
io.UnsupportedOperation: can't do nonzero end-relative seeks

以下修改后的脚本(最初由@Leos313在上面发布)应该可以解决问题

#!/usr/bin/python3

import os

dpkg_path = '/var/lib/dpkg/info/'
paths = os.listdir(dpkg_path)

for path in paths:
    full_path = os.path.join(dpkg_path, path)
    try:
        with open(full_path, 'r+b') as f:
            f.seek(0, os.SEEK_END)
            if f.tell() > 0:
                f.seek(-1, os.SEEK_END)
                last_char = f.read(1)
                if last_char != b'\n':
                    f.write(b'\n')
                    print(f'Added newline character to: {full_path}')
    except IOError as e:
        print(f"Error processing {full_path}: {e}")
    except Exception as e:
        print(f"Unexpected error processing {full_path}: {e}")
© www.soinside.com 2019 - 2024. All rights reserved.