Installing NVIDIA Drivers and CUDA on Linux Mint 21.3
If you’re a Linux Mint 21.3 user with an NVIDIA GPU, you might want to install the NVIDIA drivers and CUDA toolkit to leverage the full potential of your graphics card. This guide will take you through the step-by-step process of installing NVIDIA drivers and CUDA on your Linux Mint 21.3 system.
Prerequisites
Before you begin, ensure you have:
- Linux Mint 21.3 installed on your machine
- An NVIDIA GPU (this guide uses GeForce RTX 3060 as an example)
- Internet connection for downloading drivers and software packages
Step 1: Uninstall Existing NVIDIA Drivers
First, it’s a good idea to remove any existing NVIDIA drivers to avoid conflicts. Open a terminal and run the following commands:
sudo apt-get purge 'nvidia*'
sudo apt-get autoremove
sudo apt-get autoclean
Step 2: Add the Graphics Drivers PPA
To get the latest NVIDIA drivers, add the official graphics drivers PPA:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
Step 3: Install NVIDIA Drivers
Next, install the recommended NVIDIA drivers for your GPU. You can find the recommended driver version using the ubuntu-drivers
tool:
ubuntu-drivers devices
Look for the recommended driver version (e.g., nvidia-driver-535
). Install it by running:
sudo apt-get install nvidia-driver-535
sudo reboot
After rebooting, verify the installation with:
nvidia-smi
This command should display your GPU information and the installed driver version.
Step 4: Install CUDA Toolkit
With the NVIDIA drivers installed, you can now install the CUDA toolkit. Visit the NVIDIA CUDA Toolkit download page and download the appropriate version for your Linux Mint 21.3.
Here, we’ll use the terminal for installation. First, download the installer:
wget https://developer.download.nvidia.com/compute/cuda/12.5.0/local_installers/cuda_12.5.0_555.42.02_linux.run
Make the installer executable and run it:
chmod +x cuda_12.5.0_555.42.02_linux.run
sudo ./cuda_12.5.0_555.42.02_linux.run
Follow the on-screen instructions, ensuring you install both the driver and the toolkit.
Step 5: Set Up Environment Variables
To use CUDA, you need to set up the environment variables. Add the following lines to your ~/.bashrc
file:
export PATH=/usr/local/cuda-11.6/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Source the ~/.bashrc
file to apply the changes:
source ~/.bashrc
Step 6: Verify CUDA Installation
Check the CUDA version to ensure it’s installed correctly:
nvcc -V
You should see output similar to:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Feb_16_22:00:56_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.30978841_0
Step 7: Compile and Run a Sample CUDA Program
To ensure everything is working properly, compile and run a sample CUDA program. Create a file called sample.cu
with the following content:
#include <iostream>
__global__ void helloFromGPU() {
printf("Hello World from GPU!\n");
}
int main() {
helloFromGPU<<<1, 10>>>();
cudaDeviceSynchronize();
return 0;
}
Compile the program using nvcc
:
nvcc -o sample sample.cu
Run the compiled program:
./sample
You should see output similar to:
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Conclusion
You’ve successfully installed the NVIDIA drivers and CUDA toolkit on your Linux Mint 21.3 system. Now you can leverage the full power of your NVIDIA GPU for computational tasks, machine learning, gaming, and more. Enjoy your enhanced Linux Mint experience!
Here’s a bash script to automate the installation process: