Upgrade OpenSSL on Ubuntu 12.04

NOTICE: this question and answer pre-date the OpenSSL bug, Heartbleed.

First you need to completely remove the old installation: (this will break most systems! Be careful! Most people will regret this) apt-get purge openssl

You may want to clean house by running:

apt-get autoremove && apt-get autoclean

Then you should download and compile the version you want (full list)

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

Install the development package!

1.0.1 is part of Ubuntu 12.04 at the time of writing. However, in order to compile against it, you also have to install the development package (libssl-dev)!

First do an update of the package listing

sudo apt-get update

Then install the development package and upgrade the library itself in one go:

sudo apt-get install openssl libssl-dev

You can see here 1.0.1 is part of 12.04: http://packages.ubuntu.com/precise-updates/openssl

In case your system still installs 1.0.0, you have some other repository set up or something else in your package management is changed to cause this error. In that case, inspect what is causing it to pin on 1.0.0 still by running

apt-cache policy openssl libssl-dev