How To Install OpenCV on AlmaLinux 8

Install OpenCV on AlmaLinux 8

In this tutorial, we will show you how to install OpenCV on AlmaLinux 8. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is open-source software with bindings for C++, Python, and Java. OpenCV provides a real-time optimized Computer Vision library, tools, and hardware. It also supports model execution for Machine Learning (ML) and Artificial Intelligence (AI).

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 the OpenCV on AlmaLinux 8. You can follow the same instructions for CentOS and Rocky Linux.

Prerequisites

  • A server running one of the following operating systems: AlmaLinux 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install OpenCV on AlmaLinux 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf update
sudo dnf install epel-release
sudo dnf install opencv opencv-devel opencv-python

Step 2. Installing Dependencies.

Now we install the necessary tools and dependencies to your system:

sudo dnf install git gcc gcc-c++ cmake3 qt5-qtbase-devel python3 python3-devel python3-pip cmake python3-devel python3-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel tbb-devel libv4l-devel eigen3-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel gstreamer1-plugins-base

Step 2. Installing OpenCV on AlmaLinux 8.

Once dependencies are installed, now clone the OpenCV contrib and OpenCV repository with the following command below:

mkdir -p ~/opencv_build && cd ~/opencv_build 
git clone https ://github.com/opencv/opencv.git 
git clone https ://github.com/opencv/opencv_contrib.git

Next, create a directory temporary build, and go to that directory:

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

After that, configure the OpenCV build with the following CMake command:

cmake3 -D CMAKE_BUILD_TYPE=RELEASE \ 
-D CMAKE_INSTALL_PREFIX=/usr/local \ 
-D INSTALL_C_EXAMPLES=ON \ 
-D INSTALL_PYTHON_EXAMPLES=ON \ 
-D OPENCV_GENERATE_PKGCONFIG=ON \ 
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ 
-D BUILD_EXAMPLES=ON ..

Start the compilation process by using the following command:

make -j8 
sudo make install

Finally, we create a symlink file opencv4.pc to the directory /usr/share/pkgconfig and run ldconfig to rebuild the library’s cache.

sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/ sudo ldconfig

You can verify the OpenCV is successfully installed in your system by checking the version of the installed OpenCV:

pkg-config --modversion openc

To enable Python modules cv2 run the following command below:

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

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing the OpenCV (Open Source Computer Vision Library) on your AlmaLinux 8 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
r00t is a Server System Administrator with more than 7 years of experience in server administration, operating systems, and programming. They have a strong track record of managing, securing, and optimizing Linux-based infrastructure (Ubuntu, Debian, CentOS/AlmaLinux) as well as Windows Server, across on-premises, VPS, and cloud environments. Their expertise covers configuring and maintaining web servers (Nginx, Apache) and databases (MySQL/MariaDB, PostgreSQL). It also includes virtualization and containers (Proxmox, Docker), networking, firewalls, and security hardening. They are experienced in monitoring, backup and disaster recovery, and troubleshooting to keep services available and performing well. Skilled in Bash, Python, and PHP, they automate routine tasks, build maintenance scripts, and manage deployments, which makes operations more efficient and less error-prone. They are known for being meticulous, responsive during incidents, and willing to share knowledge with teams and the wider community. Outside of work, r00t enjoys experimenting with homelabs, open source software, and emerging infrastructure technologies.