How to install CUDA & cuDNN on Ubuntu 22.04

————install cuda———–

Install NVIDIA drivers

Update & upgrade

sudo apt update & amp; & amp; sudo apt upgrade

Remove previous NVIDIA installation

sudo apt autoremove nvidia* --purge

Check Ubuntu devices

ubuntu-drivers devices

You will install the NVIDIA driver whose version is tagged with recommended
Install Ubuntu drivers

sudo ubuntu-drivers autoinstall

Install NVIDIA drivers

My recommended version is 525, adapt to yours

sudo apt install nvidia-driver-525

Reboot & Check

reboot

after restart verify that the following command works

nvidia-smi

Install CUDA drivers
Update & upgrade

sudo apt update & amp; & amp; sudo apt upgrade

Install CUDA toolkit

sudo apt install nvidia-cuda-toolkit

Check CUDA install

nvcc --version

InstallcuDNN
Download cuDNN .deb file

You can download cuDNN file here. You will need an Nvidia account. Select the cuDNN version for the appropriate CUDA version, which is the version that appears when you run:

nvcc –version

InstallcuDNN

sudo apt install ./<filename.deb>
sudo cp /var/cudnn-<something>.gpg /usr/share/keyrings/

My cuDNN version is 8, adapt the following to your version:

sudo apt update
sudo apt install libcudnn8
sudo apt install libcudnn8-dev
sudo apt install libcudnn8-samples

Test CUDA on Pytorch
Create a virtualenv and activate it

Install pytorch

pip3 install torch torchvision torchaudio

Open Python and execute a test

import torch
print(torch.cuda.is_available()) # should be True

t = torch.rand(10, 10).cuda()
print(t.device) # should be CUDA

————————————- -Resolving Unmet Dependencies —— ——-

install cuda wrong can not find display

https://gist.github.com/hangsong/c0c3839ebfea7b683287db539785bc10
Create a file at /etc/modprobe.d/blacklist-nouveau.conf with the following contents:

blacklist nouveau
options nouveau modeset=0

1 Resolving Unmet Dependencies

https://www.baeldung.com/linux/unmet-dependencies-apt-get

2 Resolving no internet

IP:127.0.0.1
/sbin/dhcpclient
The Baeldung LogoLinux Sublogo
Start Here
About ▼
Resolving Unmet Dependencies on Linux

3 The resolution of the graphics card cannot be adjusted when installing NVIDIA in Ubuntu

  1. sudo vim /etc/default/grub

Add the following configuration (corresponding to the resolution of the monitor)

  1. GRUB_GFXMODE=1920×1080
    GRUB_GFXPAYLOAD_LINUX=1920×1080

  2. sudo update-grub

  3. Restart
    —————-
    Copyright statement: This article is an original article by CSDN blogger “Kslient” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement when reprinting.
    Original link: https://blog.csdn.net/zengfenliang/article/details/104278262
    Last updated: December 16, 2022

Written by:baeldung
Administrationapt-get
We’re looking for a DevOps engineer with bash, LAMP, and LEMP stack experience: Read More

  1. Overview
    When installing or upgrading particular packages in our system using the apt-get command, we may often run into the “unmet dependencies” error. In this tutorial, we’ll talk about what this error means and learn how to resolve it.

  2. Fixing Unmet Dependencies Error in Ubuntu
    Sometimes, when installing a package/program that is no longer supported or from a third-party dependency, we might run into this “unmet dependency” error. This happens because the apt-get command tries to install the package, but the package is looking for dependencies and can’t find available current versions of them. This error will frequently occur depending on what program we’re installing and from which dependencies it comes.

When we’re fixing this error, we should note that it’s crucial to take a backup of some of our configuration files. These files include the /etc/apt/sources.list and /var/lib/dpkg/status. Once we’ ve taken the backup, it’ll be easier to make changes if something goes wrong.

  1. Using apt-get With the -f Flag
    When we run into this error, we can use the -f flag with the apt-get command and try to correct the system, which now has broken dependencies. If successful, we’ll be able to install the package/program without experiencing this error again. Otherwise, it will throw the same error.

Let’s see the -f flag in action:

freestar

$ sudo apt-get install -f
$ sudo dpkg-configure -a
$ sudo apt-get install -f
Copy
If we get the following output after we’ve run the above commands, it means the error isn’t fixed:

0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
Copy
4. Using aptitude
Alternatively, apart from the apt-get command, we can also use aptitude. This high-level package manager will fix “unmet dependencies” errors for us. First, let’s install it:

$ sudo apt-get update
$ sudo apt-get install aptitude
Copy
After the installation is complete, let’s use aptitude to install the program that gave us the error:

$ sudo aptitude install package-name
Copy
5. Removing Held Packages
Sometimes, we may run into packages that can’t be upgraded, removed, or even changed. These are called held packages. Eliminating these kinds of packages can fix the unmet dependencies issue.

Let’s list the held packages on our system:

$ sudo apt-get -u dist-upgrade
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Calculating upgrade… Done
The following NEW packages will be installed:
linux-headers-5.15.0-52 linux-headers-5.15.0-52-generic
The following packages will be upgraded:
fonts-opensymbol libksba8 libperl5.34 libreoffice-base-core libreoffice-calc
[*list of more packages to be upgraded]
40 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
40 standard LTS security updates
After this operation, 584 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
done
Copy
If this runs successfully, it upgrades and installs the new packages. Then, the unmet dependency issue we’ll be resolved. Otherwise, it’ll list the held packages as those that are kept back:

$ sudo apt -u dist-upgrade
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Calculating upgrade… Done
The following packages were automatically installed and are no longer required:
libreoffice-impress libreoffice-math libreoffice-ogltrans
Use sudo apt autoremove’ to remove them.
The following packages have been kept back:
libreoffice-help-common libreoffice-help-en-us
thunderbird-locale-en thunderbird-locale-en-us
0 upgraded, 0 newly installed, to remove and 4 not upgraded.
Copy
Now, we’ll debug and upgrade the packages that have been kept back. Let’s run this command, after which it should remove the error:

$ sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Starting pkgProblemResolver with broken count: 0
Starting 2 pkgProblemResolver with broken count: 0
Done
Calculating upgrade… Done
The following packages were automatically installed and are no longer required:
linux-image-5.13.0-19-generic linux-modules-5.13.0-19-generic
Use sudo apt autoremove’ to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Copy
If we get the above output with nothing upgraded, installed, or removed, the command was successful. All the packages have either been upgraded, removed, or installed, and none is remaining, and the error is resolved. On the other hand, if our output still has something like:

The following packages have been kept back:
libreoffice-help-common libreoffice-help-en-us thunderbird-
locale-en thunderbird-locale-en-us
0 upgraded, 0 newly installed, to remove and 4 not upgraded.
Copy
Then the error still exists and hasn’t been resolved. And given that we now have the names of the packages causing the error, we’ll have to remove them one by one. Let’s run a mock, and if it’s successful, we proceed and remove the package:

$ sudo apt-get remove –dry-run libreoffice-help-common
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
The following packages were automatically installed and are no longer required:
linux-image-5.13.0-19-generic linux-modules-5.13.0-19-generic
Use sudo apt autoremove’ to remove them.
The following packages will be REMOVED:
libreoffice-help-common libreoffice-help-en-us
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Remv libreoffice-help-en-us [1:7.3.6-0ubuntu0.22.04.2]
Remv libreoffice-help-common [1:7.3.6-0ubuntu0.22.04.2]
$ sudo apt-get remove libreoffice-help-common
Copy
6. Clearing the Package Database
A corrupted system database can also cause the unmet dependencies error. To correct this, let’s clear out our package database:

freestar

$ sudo apt-get clean
$ sudo apt-get autoclean
Copy
The first command will clean the local repositories, except the lock files from /var/cache/apt/archives and /var/cache/apt/archives/partial. The second command will remove the outdated packages that can’t be downloaded.

  1. Removing PPAs
    Personal Package Archives (PPA) are repositories hosted on Launchpad and are used to upgrade or install packages that aren’t usually available in the official Ubuntu repositories. We’ll run into the unmet dependencies error in most instances if we use the PPA repositories to update packages existing on the official Ubuntu repositories.

7.1. Using the Terminal
Let’s list the available repositories in our Ubuntu:

$ sudo apt policy
Copy
To know which PPA repository is in our system, we look at the beginning of the lines and try to find the lines that begin with “https://ppa.*”.

Once we’ve determined the name of the PPA repository, let’s remove it:

$ sudo apt-get autoremove –purge package-name
$ sudo add-apt-repository –remove ppa:someppa/ppa
$ sudo apt-get autoclean
Copy
After that, we can check again, using the apt policy command, if the PPA repo is still there and should not appear on the list.

7.2. Using the Software Updater
We can also remove PPAs using the Software Updater application from the Ubuntu launcher. First, let’s open it by clicking and selecting the “Software Updater” icon and then clicking the “Settings…” button:

softwareupdater
Clicking “Settings” should open the window under the “Ubuntu Software” tab. On that tab, we should make sure the first two options are checked. The other two are optional, but let’s check them. We should also confirm that the download server is the “Main server”:

ubuntusoftware
After this, let’s select the “Other Software” tab. This window should be empty if there are no PPA repositories. Otherwise, if they exist, we’ll need to uncheck the selected PPAs:

ppa
Next, we click the “Close” button on the bottom right to save the changes we’ve made, and finally, click “Reload” to install updates.

  1. Conclusion
    In this article, we’ve looked at the various ways to resolve the “unmet dependency” error. We looked at using the -f flag, the aptitude command, removing held packages and PPAs, and clearing the package database. Lastly, we should keep our system up-to-date, and if we plan to use PPAs, we should ensure they’re from trusted sources.

Comments are closed on this article!
The Baeldung logo
CATEGORIES
ADMINISTRATION
FILES
FILESYSTEMS
INSTALLATION
NETWORKING
PROCESSES
SCRIPTING
SEARCH
SECURITY
WEB
SERIES
LINUX ADMINISTRATION
LINUX FILES
LINUX PROCESSES
ABOUT
ABOUT BAELDUNG
THE FULL ARCHIVE
EDITORS
TERMS OF SERVICE PRIVACY POLICY COMPANY INFO CONTACT