How to Install OpenCV on Ubuntu Using Homebrew | Fastest Beginner Method

TL;DR (Quick Answer)

If you want to install OpenCV on Ubuntu quickly, here’s the fastest way:

  1. Install Homebrew (Linuxbrew) on Ubuntu
  2. Run brew info opencv to check details
  3. Run brew install opencv to install

Requirements:

  • Ubuntu system
  • Internet connection

Time required: 5–10 minutes
Skill level: Beginner

What You’ll Learn

In this guide, you’ll learn:

  • How to install OpenCV using Homebrew on Ubuntu
  • How to avoid compiling OpenCV manually
  • How to verify your installation
  • How to fix common installation issues

Prerequisites

Before you start, make sure you have:

  • Ubuntu (20.04, 22.04, or newer)
  • Basic terminal access
  • Git and curl installed
  • A working internet connection

If you don't have the above requirements, you can run the command below in the Terminal:

sudo apt update && sudo apt install -y git curl build-essential

Step-by-Step Guide

Step 1: Install Homebrew on Ubuntu

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

Explanation:
This installs Homebrew (also called Linuxbrew), which lets you install packages easily without dealing with complex dependencies.

Step 2: Add Homebrew to PATH

echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.bashrc  
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

Explanation:
This ensures the brew command works globally in your terminal.

Step 3: Check OpenCV Package Info

brew info opencv

Explanation:
This shows details like version, dependencies, and installation path so you know exactly what you're installing.

Step 4: Install OpenCV

brew install opencv

Explanation:
This downloads and installs OpenCV along with all required dependencies automatically—no manual compilation needed.

Verification (Confirm It Works)

To verify everything is working:

Run:

opencv_version

You should see:

  • A version number (e.g., 4.x.x)
  • No errors
  • Successful import of OpenCV

What are the system requirements?

  • Ubuntu 20.04+
  • ~2–4 GB free disk space
  • Internet connection

Is there a better alternative to Homebrew?

  • APT (sudo apt install libopencv-dev) → More stable, older versions
  • Pip → Best for Python-only projects
  • Manual build → Most flexible but complex

Summary

To summarize:

  • You learned how to install OpenCV using Homebrew
  • You avoided manual compilation
  • You verified the installation using Python
  • You fixed common issues

You can now start building computer vision applications with OpenCV.

I'm Feeling Lucky
Darryl Dias

Written by Darryl Dias

The AI guy and founder of Caprycon, building AI-powered tools, exploring emerging technologies, and sharing insights from the world of artificial intelligence