Skip to content

libssl.so.1.1 缺失问题的解决方案

问题描述

升级到 Ubuntu 22.04 LTS 后,许多依赖 OpenSSL 的应用程序会出现以下错误:

ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory

这个问题是因为 Ubuntu 22.04 默认使用 OpenSSL 3.0,而许多旧版应用程序仍然依赖 OpenSSL 1.1 版本的共享库文件。

解决方案概览

针对这个问题,有几种解决方案,推荐程度从高到低排序:

  1. 安装官方 libssl1.1 包(推荐)
  2. 使用自定义库路径(安全但稍复杂)
  3. 重新编译应用程序(长期最佳方案)
  4. 重建 Python 环境(适用于 Python 项目)

安全提示

OpenSSL 1.1 已于 2023 年 9 月终止支持,建议尽可能升级应用程序以使用 OpenSSL 3.0。

方案一:安装 libssl1.1 包(推荐)

这是最简单直接的解决方案,适用于大多数情况:

bash
# 下载并安装 libssl1.1
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.23_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.23_amd64.deb

如果上述链接失效,可以访问 Ubuntu 软件包仓库查找最新版本。

替代方法:添加 Ubuntu 20.04 源

更稳定的方法是从 Ubuntu 20.04 (Focal) 的仓库安装:

bash
# 添加 Focal 安全仓库
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list

# 更新并安装
sudo apt-get update
sudo apt-get install libssl1.1

安装后可以使用以下命令验证:

bash
dpkg -L libssl1.1

应该能看到 /usr/lib/x86_64-linux-gnu/libssl.so.1.1/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 文件。

方案二:自定义库路径

如果你不想在系统目录安装旧版 OpenSSL,可以编译并放在用户目录:

bash
# 创建目录并下载源码
mkdir -p $HOME/opt && cd $HOME/opt
wget https://www.openssl.org/source/openssl-1.1.1o.tar.gz
tar -zxvf openssl-1.1.1o.tar.gz
cd openssl-1.1.1o

# 编译安装到自定义目录
./config --prefix="$HOME/opt/openssl-1.1.1o"
make
make test
make install

# 设置库路径
echo 'export LD_LIBRARY_PATH="$HOME/opt/openssl-1.1.1o/lib:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc

这种方法的好处是隔离性好,不会影响系统其他组件。

方案三:Python 环境解决方案

如果你使用的是 pyenv、poetry 等 Python 工具,可以尝试以下方法:

重新安装 Python 版本

bash
# 查看已安装版本
pyenv versions

# 重新安装特定版本
pyenv install 3.9.12
pyenv global 3.9.12

重新安装 poetry

bash
# 卸载现有 poetry
curl -sSL https://install.python-poetry.org | python3 - --uninstall

# 重新安装
curl -sSL https://install.python-poetry.org | python3 -

方案四:手动编译 OpenSSL 1.1(不推荐)

注意

此方法可能影响系统稳定性,仅在其他方法无效时考虑使用。

bash
# 下载并编译 OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1o.tar.gz
tar -zxvf openssl-1.1.1o.tar.gz
cd openssl-1.1.1o
./config
make
make test
sudo make install

# 创建符号链接
sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1

验证解决方案

无论使用哪种方法,都可以通过以下命令验证是否修复:

bash
# 检查库文件是否存在
ls /usr/lib/x86_64-linux-gnu/libssl.so.1.1
ls /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

# 或者检查 LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH

长期建议

虽然上述解决方案可以临时解决问题,但从长远来看:

  1. 更新应用程序:联系应用程序开发者,请求支持 OpenSSL 3.0
  2. 迁移到支持 OpenSSL 3.0 的版本:许多软件已发布兼容版本
  3. 定期检查依赖:确保所有组件都使用受支持的库版本

注意事项

  • 避免直接从其他系统复制库文件,可能导致兼容性问题
  • 定期检查安全更新,特别是对于已终止支持的 OpenSSL 1.1
  • 考虑使用容器化技术(如 Docker)来隔离不同版本的依赖

通过以上方法,你应该能够解决 Ubuntu 22.04 中 libssl.so.1.1 缺失的问题,同时为未来的系统升级做好准备。