编译与安装 OpenSSL

这篇文章将演示如何从源代码编译并安装 OpenSSL。

信息

截至文章更新时,OpenSSL 的最新版本为 3.5 LTS。如需要使用其他版本的 OpenSSL,请访问 OpenSSL Library Downloads 页面获取最新版本。

获取并解压源代码

1
2
3
wget -c https://github.com/openssl/openssl/releases/download/openssl-3.5.0/openssl-3.5.0.tar.gz

tar -xvf openssl-3.5.0.tar.gz

Configure

一些常见的选项有:

选项描述
--prefix=<path>指定安装目录

如果需要指定编译器,则添加环境变量 CCCXX.

1
CC=clang CXX=clang++ CFLAGS="-march=native" CXXFLAGS="-march=native" ./Configure --prefix=/opt/openssl-3.5.0

编译并安装

1
2
3
4
5
make -j$(nproc)

make test

sudo make install

找不到 pod2man ?

当您在特定的系统 (如 archlinux) 上执行 make install 时,可能会遇到 pod2man 找不到的错误。
请寻找该命令的位置并创建 symlink。

1
2
sudo find / -name pod2man
sudo ln -s <path_to_pod2man> /usr/bin/pod2man

安装结束后删除对应的 symlink 即可。

添加到环境变量

由于使用 make install 安装到 /opt/openssl-3.5.0,并不会自动添加到 PATH 中,因此需要手动添加。

相关资料

  • OpenSSL Build and Install