當前位置: 首頁>>技術教程>>正文


如何在Ubuntu上安裝OpenSSL庫?

, , ,

問題描述

我正在嘗試在使用OpenSSL 1.0.0的Ubuntu 10.04 LTS上構建一些代碼。當我運行make時,它使用”-lssl”選項調用g ++。來源包括:

#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/des.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>

我跑了:

$ sudo apt-get install openssl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openssl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

但我想openssl包不包含庫。我在make上遇到這些錯誤:

foo.cpp:21:25: error: openssl/bio.h: No such file or directory
foo.cpp:22:28: error: openssl/buffer.h: No such file or directory
foo.cpp:23:25: error: openssl/des.h: No such file or directory
foo.cpp:24:25: error: openssl/evp.h: No such file or directory
foo.cpp:25:25: error: openssl/pem.h: No such file or directory
foo.cpp:26:25: error: openssl/rsa.h: No such file or directory

如何在Ubuntu 10.04 LTS上安裝OpenSSL C++庫?

我為-l選項做了一個man g++和(在“鏈接選項”下),它指出:“鏈接器搜索庫的標準目錄列表……”和“搜索的目錄包括幾個標準係統目錄…… “那些標準係統目錄是什麽?

最佳解決辦法

您想要安裝開發包,即libssl-dev:

sudo apt-get install libssl-dev

次佳解決辦法

apt-get install libssl-dev

第三種解決辦法

How could I have figured that out for myself (other than asking this question here)? Can I somehow tell apt-get to list all packages, and grep for ssl? Or do I need to know the “lib*-dev” naming convention?

如果您要與-lfoo鏈接,那麽該庫可能是libfoo.so。庫本身可能是libfoo軟件包的一部分,並且標頭位於您發現的libfoo-dev軟件包中。

有些人使用GUI “synaptic”應用程序(sudo synaptic)來定位和安裝軟件包,但我更喜歡使用命令行。 apt-get支持bash完成,這一點使得從命令行更容易找到正確的包。

嘗試鍵入sudo apt-get install libssl,然後單擊tab以查看匹配的軟件包名稱列表(當您需要選擇具有多個版本或其他可用變體的軟件包的正確版本時,這可能會有所幫助)。

Bash完成實際上非常有用…例如,您還可以通過鍵入sudo apt-get然後點擊tab來獲取apt-get支持的命令列表。

第四種辦法

我在這裏找到了一個詳細的解決方案:Install OpenSSL Manually On Linux

來自博客文章……:

Steps to download, compile, and install are as follows (I’m installing version 1.0.1g below; please replace “1.0.1g” with your version number):

Step – 1 : Downloading OpenSSL:

Run the command as below :

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz

Also, download the MD5 hash to verify the integrity of the downloaded file for just varifacation purpose. In the same folder where you have downloaded the OpenSSL file from the website :

$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz.md5
$ md5sum openssl-1.0.1g.tar.gz
$ cat openssl-1.0.1g.tar.gz.md5

Step – 2 : Extract files from the downloaded package:

$ tar -xvzf openssl-1.0.1g.tar.gz

Now, enter the directory where the package is extracted like here is openssl-1.0.1g

$ cd openssl-1.0.1g

Step – 3 : Configuration OpenSSL

Run below command with optional condition to set prefix and directory where you want to copy files and folder.

$ ./config –prefix=/usr/local/openssl –openssldir=/usr/local/openssl

You can replace “/usr/local/openssl” with the directory path where you want to copy the files and folders. But make sure while doing this steps check for any error message on terminal.

Step – 4 : Compiling OpenSSL

To compile openssl you will need to run 2 command : make, make install as below :

$ make

Note: check for any error message for verification purpose.

Step -5 : Installing OpenSSL:

$ sudo make install

Or without sudo,

$ make install

That’s it. OpenSSL has been successfully installed. You can run the version command to see if it worked or not as below :

$ /usr/local/openssl/bin/openssl version

OpenSSL 1.0.1g 7 Apr 2014

第五種辦法

從Ubuntu上的源代碼安裝openssl庫的另一種方法,按照以下步驟操作,這裏WORKDIR是你的工作目錄:

sudo apt-get install pkg-config
cd WORKDIR
git clone https://github.com/openssl/openssl.git
cd openssl
./config
make
sudo make install
# Open file /etc/ld.so.conf, add a new line: "/usr/local/lib" at EOF
sudo ldconfig

第六種辦法

你想要openssl-devel包。至少我認為它是Ubuntu上的-devel。可能是-dev。這是兩個中的一個。

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/7120.html,未經允許,請勿轉載。