352

I'm trying to build some code on Ubuntu 10.04 LTS that uses OpenSSL 1.0.0. When I run make, it invokes g++ with the "-lssl" option. The source includes:

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

I ran:

$ 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.

But I guess the openssl package doesn't include the library. I get these errors on 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

How do I install the OpenSSL C++ library on Ubuntu 10.04 LTS?

I did a man g++ and (under "Options for Linking") for the -l option it states: " The linker searches a standard list of directories for the library..." and "The directories searched include several standard system directories..." What are those standard system directories?

jww
  • 97,681
  • 90
  • 411
  • 885
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
  • 2
    Not quite a duplicate, but answered by [What are *-devel packages?](http://stackoverflow.com/questions/2358801/what-are-devel-packages). – Troubadour Jun 10 '10 at 17:43
  • You're right about the `-dev` naming convention. You might also use the `synaptic` package manager to list all packages whose names contain libssl - browsing that list and their descriptions would likely give you the clue. – crazyscot Jun 10 '10 at 19:40
  • 1
    I know this question is quite dead by now but since I recently found it I figure someone else might too. If you want to list all packages that are similar to a certain name, I like to use >aptitude search It does not require root privilege level to run a search. – Evan Larkin Dec 07 '10 at 05:07
  • 2
    just to add to Evan's statement, recent versions of Ubuntu are coming without the aptitude command available. apt-cache search works the same way (almost) now. – Andy Feb 01 '11 at 12:15
  • 3
    In answer to your update, you could do `apt-cache search package-name` – TheDoctor Feb 23 '14 at 18:20

10 Answers10

733

You want to install the development package, which is libssl-dev:

sudo apt-get install libssl-dev
Niki Yoshiuchi
  • 16,883
  • 1
  • 35
  • 44
  • 1
    But this is not the version he wanted (1.0.0), which is not packaged for 10.04. See this answer for 1.0.0: http://stackoverflow.com/questions/3153114/how-do-i-install-and-build-against-openssl-1-0-0-on-ubuntu – nealmcb Dec 22 '10 at 06:42
  • Ah, good call. I only noticed at the time that he was trying to use the development libraries but wasn't installing the -dev package. I didn't even notice the version number. – Niki Yoshiuchi Dec 22 '10 at 15:16
  • This is the right reference here: http://www.technologyskill.ga/install-openssl-manually-on-linux/ or https://www.howtoforge.com/tutorial/how-to-install-openssl-from-source-on-linux/ libraries and header files are found under the same directory after installation: /usr/local/ssl – Mickael T Jan 22 '19 at 22:37
  • 2
    `apt install` for new dist ubuntu – AtachiShadow Feb 17 '19 at 20:18
  • Can this be installed on a specified directory? Or how can I find out where openssl is located in my system? – George Sp Apr 02 '19 at 09:14
  • @GeorgeSp you can see the list of files using `apt-file list libssl-dev` command, or here https://packages.debian.org/jessie/amd64/libssl-dev/filelist If you want to build the library yourself, please refer to one of below answers, e.g. from Mann (pay attention to step 3). – ɛIc_ↄIз Apr 04 '19 at 08:58
  • @ɛIc_ↄIз Can I create a portable directory of the library if I copy all the output from "apt-file list libssl-dev" in another directory and add it to my project? This is my main goal here, if you can suggest another way to do it, please share. – George Sp Apr 05 '19 at 15:48
  • 1
    @GeorgeSp I think so, but it's still more "natural" to build them in a custom directory using this instruction https://stackoverflow.com/a/49578644/7315276 – ɛIc_ↄIз Apr 10 '19 at 08:54
  • Worth pointing out that with Ubuntu (WSL on Windows)- I had to restart WSL in order for my build process to pick openssl up. – Rikki May 23 '23 at 03:27
65

Run:

apt-get install libssl-dev
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
24

All of these answers are very outdated and from when the package was still being developed. You can now just use the "normal" command listed below:

sudo apt install openssl

Edit: OP's question is poorly worded... after all, OpenSSL is a library itself, so I read his question too quickly before answering. The command above installs "normal" OpenSSL.

Toward the bottom of his question he mentions that make fails, suggesting he is compiling the package manually. And yes, even if you download the TAR ball, it will include all of the openssl and libssl files, which you can then make from.

What OP is really asking for is the OpenSSL Development Library, in which case you can first install OpenSSL using the above command, and then run this afterwards:

sudo apt install libssl-dev

More info: https://linuxtect.com/how-to-install-openssl-libraries-on-ubuntu-debian-mint/

Jesse Nickles
  • 1,435
  • 1
  • 17
  • 25
21

I found a detailed solution here: Install OpenSSL Manually On Linux

From the blog post...:

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

Irexiz
  • 3
  • 2
Mann
  • 211
  • 2
  • 2
  • 1
    For completeness you should include the PGP signature verification to ensure that the files signature is valid. As in https://gnupg.org/download/integrity_check.html and https://www.openoffice.org/download/checksums.html#pgp_linux – djondal Jun 06 '18 at 11:42
  • 2
    `wget http://www.openssl.org/source/openssl-3.0.7.tar.gz` for latest openssl release as of Dec. 2022 – first Dec 08 '22 at 15:18
19

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?

If you're linking with -lfoo then the library is likely libfoo.so. The library itself is probably part of the libfoo package, and the headers are in the libfoo-dev package as you've discovered.

Some people use the GUI "synaptic" app (sudo synaptic) to (locate and) install packages, but I prefer to use the command line. One thing that makes it easier to find the right package from the command line is the fact that apt-get supports bash completion.

Try typing sudo apt-get install libssl and then hit tab to see a list of matching package names (which can help when you need to select the correct version of a package that has multiple versions or other variations available).

Bash completion is actually very useful... for example, you can also get a list of commands that apt-get supports by typing sudo apt-get and then hitting tab.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Steve Lemke
  • 366
  • 1
  • 5
  • Ubuntu could ease the pain for folks since its been a problem for years. They *could* alias `openssl-dev` to `libssl-dev` but they choose not to. – jww Feb 02 '17 at 02:21
8

Another way to install openssl library from source code on Ubuntu, follows steps below, here WORKDIR is your working directory:

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
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
B.H Xie
  • 89
  • 1
  • 1
3

You want the openssl-devel package. At least I think it's -devel on Ubuntu. Might be -dev. It's one of the two.

Noordeen
  • 1,547
  • 20
  • 26
jonescb
  • 22,013
  • 7
  • 46
  • 42
1

As a general rule, when on Debian or Ubuntu and you're missing a development file (or any other file for that matter), use apt-file to figure out which package provides that file:

~ apt-file search openssl/bio.h
android-libboringssl-dev: /usr/include/android/openssl/bio.h
libssl-dev: /usr/include/openssl/bio.h
libwolfssl-dev: /usr/include/cyassl/openssl/bio.h
libwolfssl-dev: /usr/include/wolfssl/openssl/bio.h

A quick glance at each of the packages that are returned by the command, using apt show will tell you which among the packages is the one you're looking for:

~ apt show libssl-dev
Package: libssl-dev
Version: 1.1.1d-2
Priority: optional
Section: libdevel
Source: openssl
Maintainer: Debian OpenSSL Team <pkg-openssl-devel@lists.alioth.debian.org>
Installed-Size: 8,095 kB
Depends: libssl1.1 (= 1.1.1d-2)
Suggests: libssl-doc
Conflicts: libssl1.0-dev
Homepage: https://www.openssl.org/
Tag: devel::lang:c, devel::library, implemented-in::TODO, implemented-in::c,
 protocol::ssl, role::devel-lib, security::cryptography
Download-Size: 1,797 kB
APT-Sources: http://ftp.fr.debian.org/debian unstable/main amd64 Packages
Description: Secure Sockets Layer toolkit - development files
 This package is part of the OpenSSL project's implementation of the SSL
 and TLS cryptographic protocols for secure communication over the
 Internet.
 .
 It contains development libraries, header files, and manpages for libssl
 and libcrypto.

N: There is 1 additional record. Please use the '-a' switch to see it
Vincent Fourmond
  • 3,038
  • 1
  • 22
  • 24
1
  1. Go to the official website and download the source code for the version you need

  2. Then unzip the update package and execute the following command

    ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl  -Wl,-rpath,/usr/local/ssl/lib shared
    

Because the default is to generate only static libraries, if you want dynamic libraries, add the "shared" option

  1. make && make install
JK.Tang
  • 11
  • 2
  • Every time you `make install`, one kitten dies... It's better to use `checkinstall`, if you're not satisfied with packages you have in repos. – k.meinkopf Jul 09 '21 at 05:46
-3

sudo apt-get install libcurl4-openssl-dev

Noordeen
  • 1,547
  • 20
  • 26