Sling Academy
Home/DevOps/How to Install/Upgrade OpenSSL with Homebrew

How to Install/Upgrade OpenSSL with Homebrew

Last updated: January 28, 2024

OpenSSL is an open-source cryptographic library and tool that is widely used for secure communication over networks. Ensuring that it’s up-to-date is crucial for security. macOS users can easily install and upgrade OpenSSL using Homebrew, the popular package manager for macOS (and now Linux). In this tutorial, I will guide you through the process of installing and upgrading OpenSSL on your macOS machine using Homebrew, with step-by-step instructions and code examples.

Prerequisites

Before beginning this tutorial, you should have the following:

  • A macOS system
  • Access to terminal
  • Homebrew installed (installation instructions can be found at the official Homebrew website)

Installing Homebrew

If you haven’t already installed Homebrew, you can do it by pasting the following command into your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Homebrew makes it straightforward to install and keep OpenSSL up-to-date. To proceed, please ensure Homebrew is installed by running:

brew --version

You should see an output similar to:

Homebrew 3.X.Y
Homebrew/homebrew-core (git revision abcde; last commit 2023-04-01)

Installing OpenSSL

To install OpenSSL with Homebrew, execute:

brew install openssl

Homebrew will download and install the latest OpenSSL version along with its dependencies. Upon completion, you should see a summary like:

==> Downloading https://homebrew.bintray.com/bottles/openssl-X.Y.Z.mojave.bottle.tar.gz
==> Pouring openssl-X.Y.Z.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/openssl/X.Y.Z: 1,793 files, 12MB

Note: X.Y.Z is a placeholder for the installed version number.

Configuring OpenSSL Path

Once installed, you may need to adjust your PATH environment variable to ensure your system uses the Homebrew-installed version of OpenSSL. To accomplish this, add the following line to your ‘.bash_profile’ or ‘.zshrc’ (depending on your shell):

echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

Reload your profile or open a new terminal session to apply these changes.

Upgrading OpenSSL

To ensure you have the latest OpenSSL version installed via Homebrew, first update Homebrew’s formulae:

brew update

Then, upgrade OpenSSL:

brew upgrade openssl

Homebrew will update your OpenSSL installation to the latest version and show you an output like:

==> Upgrading openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-X.Y.Z_1.mojave.bottle.tar.gz
==> Pouring openssl-X.Y.Z_1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/openssl/X.Y.Z_1: 1,793 files, 12MB

If no upgrade is necessary, Homebrew will tell you so:

Warning: openssl X.Y.Z_1 already installed

Verifying the Installation

After the installation or upgrade, you can verify that the correct version of OpenSSL is installed by running:

openssl version

You should see something akin to:

OpenSSL 1.1.1k  25 Mar 2021

Advanced Usage

Advanced users may need to link applications against the Homebrew version of OpenSSL due to version requirements. Make sure to consult documentation relevant to your development environment or application for specific instructions on how to handle these dependencies. Here’s an example of fixing a compile issue with a version mismatch:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

Some users may also want to set the PKG_CONFIG_PATH environment variable to help ‘pkg-config’ find the OpenSSL library:

export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

Homebrew also enables you to switch between different OpenSSL versions when necessary, which can be particularly useful if you are testing against multiple versions:

brew switch openssl X.Y.Z

Always be aware that OpenSSL updates are often related to security fixes. Avoid using outdated versions if not necessary for compatibility reasons.

Conclusion

In this tutorial, we’ve demonstrated how to install and keep OpenSSL up-to-date using Homebrew. This process simplifies the management of essential security tools on a macOS environment, enabling you to focus on development with confidence.

Next Article: Homebrew Error: The brew link step did not complete successfully

Previous Article: Homebrew: Check for outdated packages and upgrade them

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide