Linux MintUbuntu Based

How To Install OpenCV on Linux Mint 21

Install OpenCV on Linux Mint 21

In this tutorial, we will show you how to install OpenCV on Linux Mint 21. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is a powerful open-source library used for computer vision, machine learning, and image processing. It plays a significant role in real-time operations, which are crucial in today’s systems. By using OpenCV, one can process images and videos to identify objects, faces, or even human handwriting. When integrated with various libraries, such as Numpy, Python can process the OpenCV array structure for analysis.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of OpenCV on a Linux Mint 21.2 (Victoria).


  • A server running one of the following operating systems: Linux Mint 21.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install OpenCV on Linux Mint 21

Step 1. Before installing any new software, it’s always a good idea to update your system. This ensures that you have the latest security patches and software updates. Use the following command to update your system:

sudo apt update
sudo apt upgrade

Step 2.Installing Python and PIP.

Before installing OpenCV, ensure that Python and PIP are preinstalled on your system. You can check if Python is already installed by opening the terminal and running the following command:

python --version

If Python is not present, you will need to install it. Similarly, to check if PIP is installed, run the following command:

pip3 --version

Step 3. Installing Required Dependencies.

OpenCV relies on other libraries to function properly. Install the required dependencies:

sudo apt install libgtk-3-dev libboost-all-dev libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libopenexr-dev python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev

Step 4. Installing OpenCV on Linux Mint 21.

Clone the OpenCV and OpenCV contrib repository to get the latest source files:

mkdir ~/opencv_build && cd ~/opencv_build
git clone
git clone

Build OpenCV with CMake and use make to compile the source code:

cd ~/opencv_build/opencv
mkdir build && cd build

      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \

make -j$(nproc)
sudo make install

This will install OpenCV to /usr/local/ by default.

Check that OpenCV is installed correctly by importing cv2 in Python:

python3 -c "import cv2; print(cv2.__version__)"

This should print out the OpenCV version installed.

You can also run some of the examples in /usr/local/share/opencv4/samples/python to verify OpenCV is working properly.

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial to install the latest version of OpenCV on the Linux Mint system. For additional help or useful information, we recommend you check the official OpenCV website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button