You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Ubuntu 22.04 LTS中MongoDB源文件格式错误的APT报错

Ubuntu 22.04 LTS安装MongoDB时apt-update报错解决方案

报错信息翻译

E: Malformed entry 1 in list file /etc/apt/sources.list.d/mongo.list ([option] not assignment)
E:The list of sources could not be read

翻译内容:

E: 源文件/etc/apt/sources.list.d/mongo.list的第1条条目格式错误(选项未正确赋值)
E: 无法读取源列表

问题根源

你执行的添加MongoDB源的命令存在格式错误:signed-by参数前的方括号后多了一个空格,同时arch和signed-by两个选项之间的空格缺失,导致apt无法正确解析源条目。

修复步骤

  • 删除错误的源文件:
    sudo rm /etc/apt/sources.list.d/mongo.list
    
  • 重新添加格式正确的MongoDB源:
    sudo sh -c 'echo "deb [ arch=amd64,arm64 signed-by=/etc/apt/keyrings/mongodb.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" >> /etc/apt/sources.list.d/mongo.list'
    
  • 再次执行更新命令:
    sudo apt-get update
    

补充说明

如果还未导入MongoDB的GPG密钥,需先执行以下命令(否则可能出现密钥验证失败的报错):

curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg -o /etc/apt/keyrings/mongodb.gpg --dearmor

内容的提问来源于stack exchange,提问作者user14798306

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 11:47:34