Compiling GDAL using proprietary library to support ECW file format
QGIS uses GDAL for file formats. Tested and works also on Ubuntu 22.04.
# First download zip file bellow (will have to create an account)
https://download.hexagongeospatial.com/downloads/ecw/erdas-ecw-jp2-sdk-v5-4-linux
unzip erdas-ecw-sdk-5.4.0-linux.zip
chmod +x ERDAS_ECWJP2_SDK-5.4.0.bin
# Run bin - Choose Option 1. Desktop_Read-Only
./ERDAS_ECWJP2_SDK-5.4.0.bin
# Copy installed files to /usr/local
sudo cp -r hexagon/ERDAS-ECW_JPEG_2000_SDK-5.4.0/Desktop_Read-Only/ /usr/local
# Make symbolic link to libNCSEcw.so.5.4.0
sudo ln -s /usr/local/Desktop_Read-Only/lib/newabi/x64/release/libNCSEcw.so.5.4.0 /usr/local/lib/libNCSEcw.so.5.4.0
# Download and install proper PROJ version
# QGIS 3.22.4 uses gdal 8.2.1
# from https://github.com/OSGeo/PROJ/releases. and unzip it
cd proj-8.2.1
mkdir build
cd build
cmake ..
make -j$(nproc)
sudo make install
# Downlad GDAL for specific QGIS version
# QGIS 3.22.4 uses gdal 3.4.1
wget -c http://download.osgeo.org/gdal/3.4.1/gdal-3.4.1.tar.gz
tar -xvzf gdal-3.4.1.tar.gz
cd gdal-3.4.1
./configure --with-ecw=/usr/local/lib/libNCSEcw.so.5.4.0
# Compile- takes a lot of time...
make -j$(nproc)
sudo make install
# Set variables
echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> ~/.profile
echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc
GDAL_DATA="/usr/local/share/gdal"
ldconfig
# Check if ECW is installed
gdalinfo --formats | grep ECW
Based and updated from here.