第 3 節

Install required configuration

0瀏覽次數0訪問次數--跳出率--平均停留

  Software package source replacement (using Debian-based distributions as an example)

Open the website below (note: this Ubuntu repository version is for X86, amd64 architecture. The ARM repository is not on this website (99.9% of people's computers are X86, and many industrial PCs are ARM, but there are also X86 industrial PCs. Please refer to the Vinci Robotics Team Microcontroller Tutorial to learn more, or search on Baidu yourself.)

Just pick one of the mirror sources below.

https://mirrors.bfsu.edu.cn/help/ubuntu/

https://mirrors.cloud.tencent.com/help/ubuntu.html

https://developer.aliyun.com/mirror/ubuntu

https://mirrors.sustech.edu.cn/help/ubuntu.html#introduction

https://mirrors.ustc.edu.cn/help/ubuntu.html

https://help.mirrors.cernet.edu.cn/ubuntu/

It can measure speed and select the fastest source.

curl https://mirrors.cernet.edu.cn/oh-my-mirrorz.py | python3

Speed test results in the north (Shandong) are as follows:

In the south (Guangdong), the speed test results are as follows:

The faster ones in both the north and south are 北京外国语大学BFSU and 南方科技大学SUSTech. If you don't want to test speeds, you can pick them without hesitation, or you can test speeds to choose the best source.

  Ubuntu 22.04 (and Debian 10) and earlier versions

Enter the following command

sudo apt update
sudo apt install vim
sudo vim /etc/apt/sources.list

In the following interface, press ggdG on the keyboard (note: case-sensitive).

Once you have selected the Ubuntu version,

I'll be happy to help you translate Simplified Chinese Markdown fragments into natural American English. Please paste the text you'd like me to translate.

Press ESC, then type a colon in English, enter :wq! and press Enter.

Enter the following command

sudo apt update

If the corresponding school source website appears below, it is successful.

At this point, the source switching is complete.

  Ubuntu 24.04 (and Debian 12) and later versions

sudo apt update
sudo apt install vim
sudo rm -rf /etc/apt/sources.list
sudo rm -rf /etc/apt/sources.list.d/**

sudo vim /etc/apt/sources.list.d/ubuntu.sources

Once you have selected the Ubuntu version, copy the content below.

I'll be happy to help you translate Simplified Chinese Markdown fragments into natural American English. Please paste the text you'd like me to translate.

Press ESC, then type a colon in English, enter :wq! and press Enter.

Enter the following command

sudo apt update

If the corresponding school is substituted here, it will succeed.

Fedora 41 (DNF5) and later

https://mirrors.bfsu.edu.cn/help/fedora/

https://help.mirrors.cernet.edu.cn/fedora/

sed -e 's|^metalink=|#metalink=|g' \
    -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.bfsu.edu.cn/fedora|g' \
    -i.bak \
    /etc/yum.repos.d/fedora.repo \
    /etc/yum.repos.d/fedora-updates.repo

Remove the disgusting snap (Ubuntu derivative)

⚠️ Official default original Ubuntu Gnome
Do not uninstall snap, or you'll be screwed. The original Ubuntu leaves you no choice but to let snap keep annoying you. (Now it seems even non-original Ubuntu doesn't allow uninstalling it either—so frustrating.)

That's why I've always recommended Ubuntu KDE (also known as Kubuntu).

Install a non-Firefox browser

Before uninstalling snap, please install a browser first (using Google Chrome as an example) (this is because Ubuntu comes with the snap version of Firefox by default).

The following is the Chrome official website hosted on Google's Shanghai server (no VPN required).

https://www.google.cn/chrome/index.html

Since we're using Ubuntu, which is a Debian-based system, select the package with the .deb extension (highlighted in the red box).

For Red Hat-based systems, you need to install packages with the .rpm extension (shown in the blue box).

#某些发行版中,可能Downloads是中文下载,所以就需要  cd ~/下载
cd ~/Downloads
#下方chrome安装包名不一定是这个,根据名字来看
sudo apt install ./google-chrome-stable_current_amd64.deb

Check the number of snap package applications.


# 老版
sudo apt update
sudo apt install neofetch
neofetch

# 新版
sudo add-apt-repository ppa:zhangsongcui3371/fastfetch
sudo apt update
sudo apt install fastfetch
fastfetch

# windows 想看系统信息的话
winget install fastfetch
#重启 powershell
fastfetch

Here it shows a total of 3162 Debian programs and 7 Snap programs.

Remove the snap application.

When the system boots, it automatically starts Snap-related services. Let's disable these services first.

sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.seeded.service

Then view the list of snap applications.

Depending on your installation choice (minimal or normal installation), different Snap software will be pre-installed on the system. Before removing the Snap service, we need to remove these Snap installations.


# 查询当前系统上snap安装了哪些app
snap list

Delete all applications shown in the image, following the order of deleting application software first, then non-application software.

#移除snap-store,如果是Kubuntu,则没有这个东西,测不需要卸载
sudo snap remove snap-store
#移除firefox浏览器 gnome-42-2204 gtk-common-themes(可以一次性移除多个)
sudo snap remove firefox gnome-42-2204 gtk-common-themes
#移除其它...

#移除core22,bare以及snapd(下面这些需要最后再移除,否则会报错)
sudo snap remove core22
sudo snap remove bare
sudo snap remove snapd

Run the following command to check if there are any remaining snap packages.

snap list

# 老版
neofetch

# 新版
fastfetch

Remove snap

After removing software installed via Snap, the next step is to remove Snap itself. This needs to be done using Apt (proceed with caution, as the visual interface may crash).

 #使用apt移除掉snap
sudo apt autoremove --purge snapd
#移除snapd的一些目录
sudo rm -rf /var/cache/snapd
sudo rm -rf ~/snap

At this point, Snap has actually been removed. However, this is not enough — if you use apt to install certain software sudo apt install firefox, it will automatically download and reinstall the Snap service. This is because some software in the Ubuntu repositories is already the Snap version rather than the Deb version. When downloading the Snap version, the system will automatically check and, if necessary, reinstall the Snap service. This is part of Canonical's extra effort to promote its own Snap Store. (This is one aspect that many people dislike the most.)

Prohibit the system from automatically installing snap.

We can use APT's configurable feature to disable the installation of specific dependencies, thereby preventing the automatic reinstallation of the Snap service.

sudo vim /etc/apt/preferences.d/nosnap.pref

Press Insert to enter edit mode, then copy the following content. Finally, press ESC, switch to English input mode, and type :wq followed by Enter.

Package: snapd
Pin: release a=*
Pin-Priority: -10

Test if successful

sudo apt update
sudo apt install firefox

Here, the prompt indicates that snapd cannot be installed, which proves success.

Reinstall the Firefox browser (not really necessary)

I personally prefer Google Chrome, which I installed by downloading the deb package from the Chrome official website. Since I already have a browser, there's no need to install Firefox.

But if you really like Firefox, after removing Snap, you actually can't install Firefox through Snap or Apt anymore. The download provided by Firefox's official website doesn't include a .deb package or a desktop shortcut, which isn't very convenient.

So, you can consider using the source provided by Mozilla to install the Debian version of Firefox.


# 添加Mozilla提供的源
sudo add-apt-repository ppa:mozillateam/ppa

# 安装Firefox
sudo apt update
sudo apt install firefox

Cross-major version Ubuntu update

Cross-major version Ubuntu updates refer to major version upgrades, such as updating from Ubuntu 22.04 LTS to Ubuntu 24.04 LTS.

When performing a major Ubuntu version upgrade, it is recommended to restore snap, and then remove it after the upgrade is complete, to prevent Canonical from causing trouble.

#删掉禁止安装snap的配置文件
sudo rm -rf /etc/apt/preferences.d/nosnap.pref
sudo apt update

sudo apt dist-update

Switch the system language to Chinese.

(If you really don't like English, you can switch. Using KDE6 as an example, others are similar.)

Chinese input method

Download Sogou Input Method from the official website.

Open the terminal and enter the following:

cd ~/Downloads/
sudo apt install ./sogoupinyin_4.2.1.145_amd64.deb

Open Fcitx.

Add Sogou Input Method

Set Sogou Input Method as the default input method.

Fcitx5 (Ubuntu 22.04 and above, Debian 12 and above, Fedora)

  1. Uninstall the old input method

# Ubuntu或者Debian
sudo apt purge fcitx* ibus*

# Fedora

# 应该不用干任何事,fedora41基本都移除了
  1. Install Fcitx5

# Ubuntu22.04及以上、Debian12及以上
sudo apt install fcitx5 fcitx5-chinese-addons

# Ubuntu20.04
sudo add-apt-repository ppa:zhsj/fcitx5
sudo apt update
sudo apt install fcitx5 fcitx5-chinese-addons

# Fedora
sudo dnf install fcitx5 fcitx5-chinese-addons fcitx5-autostart
  1. Reboot System
  2. Start Fcitx5

  1. Modify some settings

Add Pinyin and Keyboard - English US to the left side. (If you can't find them, do not check "Show only current language" on the right.)

Added keyboard shortcuts for easier switching between Chinese and English.

  1. Configure environment variables
    1. If you are using KDE + Wayland, you also need the following step (Kubuntu 26.04 and above, Debian 13 and above, Rocky 10 and above, Fedora, etc.)


    1. If you are using KDE+X11, you will also need the following step (on most older versions of distributions, you can use fastfetch to check whether you are using x11 or wayland).
    vim ~/.config/plasma-workspace/env/fcitx5.sh
    
    export GTK_IM_MODULE=fcitx
    export QT_IM_MODULE=fcitx
    export XMODIFIERS="@im=fcitx"
    export SDL_IM_MODULE=fcitx
    export INPUT_METHOD=fcitx
    

Restart again.

  1. Restart
sudo shutdown -r now
  1. Optimize Fcitx5 using the Fcitx5 Configuration Tool (go to GitHub and read the instructions to install it yourself).

https://github.com/debuggerx01/fcitx5\_customizer


# Ubuntu

# 直接在线执行工具箱优化
curl -sSL https://fcitx5.debuggerx.com/fcitx5_customizer.sh | bash -s -- recommend

# Fedora

# 直接在线执行工具箱优化
curl -sSL https://fcitx5.debuggerx.com/fcitx5_customizer.sh | bash -s -- recommend
  1. Restart again.
sudo shutdown -r now

Replace the pip3 source.

Non-Debian-based distributions need to do this.

Distributions like Ubuntu and Debian that use the apt tool do not require this operation.

Systems using dnf (such as Fedora, RHEL, Rocky Linux) may also be able to skip this step.

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

Follow the order shown in the diagram, but as expected, it will throw an error because most distributions don't come with pip pre-installed. So please continue reading below.

#安装pip3
sudo apt update
sudo apt-get install python3-pip

#更新pip3
python3 -m pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple --upgrade pip

#设置pip源为北京外国语大学镜像源
pip3 config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple

#测试
python3 -m pip install --upgrade pip

If successful, you will see the word "bfsu" after "Looking".

Install RPMFusion and change the source.

(For Red Hat-based systems only; Ubuntu and other Debian-based systems do not need this.)

https://mirrors.bfsu.edu.cn/help/rpmfusion/

  1. First, use the following command to check if you have enabled rpmfusion.
rpm -qa | grep rpmfusion

  1. If it is enabled, first uninstall rpmfusion.
sudo dnf remove rpmfusion-free-release rpmfusion-nonfree-release

  1. Install the rpmfusion from Beijing Foreign Studies University.
    1. Fedora
    
    # 安装免费仓库非免费仓库
    sudo dnf install --nogpgcheck https://mirrors.bfsu.edu.cn/rpmfusion/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.bfsu.edu.cn/rpmfusion/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
    
    1. RHEL、RockyLinux
    
    # 安装免费仓库非免费仓库
    sudo dnf install --nogpgcheck https://mirrors.bfsu.edu.cn/rpmfusion/free/fedora/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.bfsu.edu.cn/rpmfusion/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm
    
  2. Change the other RPM Fusion repositories to the BFSU mirror as well.
sudo sed -e 's!^metalink=!#metalink=!g' \
         -e 's!^mirrorlist=!#mirrorlist=!g' \
         -e 's!^#baseurl=!baseurl=!g' \
         -e 's!https\?://download1\.rpmfusion\.org/!https://mirrors.bfsu.edu.cn/rpmfusion/!g' \
         -i /etc/yum.repos.d/rpmfusion*.repo
  1. Check the updated repository.
grep "mirrors.bfsu" /etc/yum.repos.d/rpmfusion*.repo

You can see that not only the free and nonfree sources have changed, but NVIDIA and Steam have also been updated.

  1. Refresh the repository cache.
sudo dnf clean all
sudo dnf makecache

Time out of sync

Dual-booting causes Ubuntu to be 8 hours ahead of Windows, while Windows is 8 hours behind Ubuntu, so the system time synchronization issue needs to be resolved. It's still the same video shared the first time, and there's a section later on that covers the time synchronization problem.

(Suggestion: Turn on subtitles while watching, as some unexpected issues may be explained in the bullet comments.)

https://www.bilibili.com/video/BV1554y1n7zv/?vd\_source=ceb9c29ca8792358f229b53eef0c1448

Installation of the graphics card driver

Completely uninstall the graphics card driver.


# 如果使用了.run文件进行安装的,再使用下面命令卸载干净
sudo /usr/bin/nvidia-uninstall

# 如果是使用apt安装的驱动
sudo apt-get remove --purge nvidia*

# 如果是使用dnf安装的驱动
sudo dnf remove nvidia*

Frequently Asked Questions (Check back here if you run into issues)

  1. Disable the open-source driver nouveau, as it often causes lag, black screens, and screen artifacts.
sudo vim /etc/modprobe.d/blacklist-nouveau.conf

The contents of the blacklist-nouveau.conf file are as follows:

blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

Next, run the following command


# debian系选这个(Ubuntu等)
sudo update-initramfs -u

# 红帽系选这个(Fedora,Rocky等)
sudo dracut --force

# 重启
sudo reboot

After rebooting, check whether nouveau is still active. If nothing appears, it means the disable was successful.

lsmod | grep nouveau
  1. Unable to adjust screen brightness, unable to use HDMI port (this is because the xorg file and grub are not configured) ( X11 only , for example Ubuntu 24.04 and below; distributions like Fedora that use Wayland cannot use the configuration below.)

First, configure xorg.

sudo vim /usr/share/X11/xorg.conf.d/10-nvidia.conf

Then modify the content in 10-nvidia.conf to the content below and save it, then restart.

Section "OutputClass"
   Identifier "nvidia"
   MatchDriver "nvidia-drm"
   Driver "nvidia"
   Option "AllowEmptyInitialConfiguration"
   Option "PrimaryGPU" "yes"
   ModulePath "/usr/lib/x86_64-linux-gnu/nvidia/xorg"
EndSection

# 或者

Section "OutputClass" 
    Identifier     "nvidia" 
    MatchDriver    "nvidia-drm" 
    Driver         "nvidia" 
    Option         "RegistryDwords" "EnableBrightnessControl=1;PrimaryGPU=1" 
    Option         "Backlight" "nvidia_0" 
    ModulePath     "/usr/lib/x86_64-linux-gnu/nvidia/xorg" 
EndSection

Reconfigure grub

sudo vim /etc/default/grub

Add the following parameters to the grub parameters. Note that these should be added, not replaced — the original parameters must be retained.

GRUB_CMDLINE_LINUX_DEFAULT="nvidia.NVreg_EnableBacklightControl=1 acpi_backlight=native video.use_native_backlight=0"


# debian系选这个(Ubuntu等)
sudo update-initramfs -u
#或
sudo update-grub

# 红帽系选这个(Fedora,Rocky等)
sudo dracut --force

sudo reboot

Just restart.

  1. An error occurred while installing the NVIDIA graphics driver.
Unable to find the kernel source tree for the currently running kernel.  Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed.If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option.
  1. Check the currently running kernel version:

Run the following command to check which kernel version you are currently using:

uname -r
  1. Install kernel development files:

Make sure you have installed the kernel-devel package that matches the current kernel version. Run the following command to install it:

sudo dnf install kernel-devel-$(uname -r)

This will automatically install the kernel development package that matches your current kernel version.

  1. Install kernel source code (optional):

If you need to access the complete kernel source code, you can run the following command to install it:

sudo dnf install kernel-headers kernel-source
  1. Check the installation.

After installation, confirm that the path is correct. The kernel source files are typically located in the /usr/src/kernels/ directory. You can use the following command to check if the directory exists:

ls /usr/src/kernels/

If you still encounter issues, you can manually specify the kernel source file path using the --kernel-source-path option.

Installation Method Recommendation

Below are three methods for installing the driver, all covered in the tutorial: the general method, the APT method, and the DNF method.

Beginners are advised to install NVIDIA drivers using APT (on Ubuntu or Debian) or DNF (on Fedora or Rocky Linux), then install CUDA using the general method, and continue to install cuDNN using APT or DNF.

(If you are a beginner, strictly follow the installation method recommended in the table below—don't try to improvise.)

The recommended method for each distribution
NVIDIA driver
CUDA
cuDNN

APT installation (Method 1: Suitable for Debian, Ubuntu, etc.)

Install the graphics card driver

With this method of installing the graphics driver, you won't need to reinstall the driver after future kernel updates.

Ubuntu

# 安装英伟达驱动
sudo apt install nvidia-driver-版本号

# 重启 (必须重启)
sudo shutdown -r now

# 检查驱动是否安装成功
nvidia-smi
Debian

# 安装内核头文件和编译工具
sudo apt install -y linux-headers-amd64 build-essential

# 安装英伟达驱动
sudo apt install nvidia-driver

# 重启
sudo shutdown -r now

# 检查驱动是否安装成功
nvidia-smi
Install CUDA

(Please use Method 1: General Approach)

Install cuDNN

Choose CuDNN v9 (the installation process for this version is similar to CUDA, and you can follow the official tutorial to install it).

https://developer.nvidia.com/cudnn-archive

DNF Installation (Method 2: Suitable for Fedora, Rocky, etc.)

Install the graphics card driver

If we install the graphics driver using the general method, we'll find that the driver drops every time Fedora updates the kernel. How do we solve this? Please install the graphics driver using DNF.

With this method of installing the graphics driver, you won't need to reinstall the driver after future kernel updates. (After installing a new kernel, the akmod build process is automatically triggered upon reboot. At that point, the system generates NVIDIA driver modules that match the new kernel.)

Note: Before installing the driver, make sure you haven't installed a driver using methods like .run. You can check with the nvidia-smi command. If it indicates no driver is installed, you're good to go. If it shows a driver is already installed, please uninstall it first (the uninstall tutorial should be above) or wait for the next kernel update (a kernel update will remove drivers installed via .run).

Fedora

# 启用 RPM Fusion 仓库(北京外国语源)
sudo dnf install --nogpgcheck https://mirrors.bfsu.edu.cn/rpmfusion/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.bfsu.edu.cn/rpmfusion/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

# 安装驱动和内核工具
sudo dnf install akmod-nvidia  # 自动适配内核的驱动(重点)
sudo dnf install xorg-x11-drv-nvidia-cuda  # 包含 CUDA 支持

# 重启并验证(这种方式必须重启)
sudo reboot
nvidia-smi  # 检查驱动版本(如 570.86.16)
Install CUDA

After installing the graphics driver via dnf, you can also use the general method to install CUDA. This approach is also very convenient (CUDA will not be lost after a kernel update).

You can also use the following dnf method to install CUDA.

(This tutorial uses Fedora 41 and RTX 3060 Laptop as an example) (Rocky and RHEL are similar).

  1. First, check the highest CUDA version supported by the graphics card driver.
nvidia-smi

On the left is the NVIDIA driver version, and on the right is the highest supported CUDA version. Note that this is the maximum version — any CUDA version lower than this can be installed. (There's no need to chase the latest; stability is what matters, though all versions are quite stable.)

  1. Download CUDA and install CUDA

https://developer.nvidia.com/cuda-toolkit-archive

Select a version, using CUDA 12.4 as an example (the green boxes indicate versions installable on this computer, while the red box indicates versions that are not).

I have an Intel CPU (X86_64 architecture, also called amd64), so I choose X86_64. (Both AMD and Intel are X86. If you're unsure, see the Vinci Robotics Team Microcontroller Tutorial.)

I'm using Fedora 41, so I selected Fedora 41 (if you're using RockyLinux, select RockyLinux) as shown below:

https://developer.nvidia.com/cuda-toolkit-archive

Type it according to the corresponding section of the website, as shown in my image above:

wget https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda-repo-fedora41-12-8-local-12.8.0_570.86.10-1.x86_64.rpm
sudo dnf install ./cuda-repo-fedora41-12-8-local-12.8.0_570.86.10-1.x86_64.rpm
sudo dnf clean all
sudo dnf -y install cuda-toolkit-12-8

Perform environment configuration:

sudo vim ~/.bashrc

Copy the following line into the ~/.bashrc file and save it. If you don't know how to use the vim editor, please search online.

export PATH=/usr/local/cuda-12.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64:$LD_LIBRARY_PATH

Or (the one below is recommended)

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH


# 刷新当前终端的环境变量
source ~/.bashrc

# 验证CUDA是否安装成功
nvcc -V

If the image below appears, the installation was successful.

Install cuDNN

Choose CuDNN v9 (the installation process for this version is similar to CUDA, and you can follow the official tutorial to install it).

https://developer.nvidia.com/cudnn-archive

Common Method (Method 3: Script or Archive Method)

If you encounter any issues, please refer to the FAQ section to see if there is a corresponding solution. (The FAQ for Ubuntu, Debian, Fedora, and Rocky should be comprehensive.)

Install the graphics card driver

To install using this method, you first need to disable nouveau. Please scroll down and find the section Frequently Asked Questions (one or two sections above) to disable nouveau.

First, download the Nvidia driver with the .run extension.

https://www.nvidia.cn/drivers/lookup/

Use the following command to stop the visual desktop environment (you can also use Ctrl+Alt+F*). You may also skip disabling the desktop environment and proceed directly to the next step.


# 通用的命令(sudo telinit 5是打开图形界面)
sudo telinit 3

# ubuntu 使用下方命令
sudo service lightdm stop

# Fedora 使用下方命令
sudo systemctl isolate multi-user.target

Afterwards, a new command line session will start, logging in with the current username and password. (Do not use the root user)


# 编译环境+准备工作
sudo apt install build-essential

# 进入到.run目录中
cd /home/tungchiahui/Downloads/

# 给驱动文件增加可执行权限:
sudo chmod a+x NVIDIA-Linux-x86_64-550.107.02.run

# 然后执行安装:
sudo ./NVIDIA-Linux-x86_64-550.107.02.run

# 如果有异常则:(一般不用下方这条,会导致OPENGL没法被安装,这样ROS有些功能无法使用)
sudo ./NVIDIA-Linux-x86_64-550.107.02.run  --no-opengl-files

After installation, restart to finish.


# 重启 
sudo reboot

# 检查驱动是否安装成功
nvidia-smi
Install CUDA

(This tutorial uses Debian 12 Bookworm and RTX3060 Laptop as an example) (Ubuntu and Fedora are similar)

  1. First, check the highest CUDA version supported by the graphics card driver.
nvidia-smi

On the left is the NVIDIA driver version, and on the right is the highest supported CUDA version. Note that this is the maximum version — any CUDA version lower than this can be installed. (There's no need to chase the latest; stability is what matters, though all versions are quite stable.)

  1. Download CUDA and install CUDA

https://developer.nvidia.com/cuda-toolkit-archive

Select a version, using CUDA 12.4 as an example (the green boxes indicate versions installable on this computer, while the red box indicates versions that are not).

I have an Intel CPU (X86_64 architecture, also called amd64), so I choose X86_64. (Both AMD and Intel are X86. If you're unsure, see the Vinci Robotics Team Microcontroller Tutorial.)

I'm using Debian 12, so I selected Debian 12 (if you're using Ubuntu, select Ubuntu). As shown in the image below, it's recommended to choose the runfile for installation.

Type the command in the box below into the terminal.


# 在当前文件夹下创建一个ttt的子文件夹
mkdir -p ./ttt

# 进入ttt文件夹
cd ttt

# 输入复制的第一条命令(用来下载cuda的runfile文件)
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_550.54.14_linux.run

# 给予权限
sudo chmod a+x ./cuda_12.4.0_550.54.14_linux.run

# 运行脚本
sudo ./cuda_12.4.0_550.54.14_linux.run

Loading...

accept and proceed

Since we have already installed the driver, remove that option and just click Install. (Be sure not to select the driver installation — beginners should avoid unnecessary trouble.)

After waiting a moment, if no red text appears, the installation is generally successful. You can read the English text to confirm (and also verify the location).

  1. Set up the environment

Please confirm the path based on the above, such as the one I highlighted in red above.

Please make sure that - PATH includes /usr/local/cuda-12.4/bin - LD_LIBRARY_PATH includes /usr/local/cuda-12.4/lib64, or, add /usr/local/cuda-12.4/lib64 to /etc/ld.so.conf and run ldconfig as root

If you forgot to check earlier, you can also use the following command to view the path:

which nvcc

So I performed the following operations:

sudo vim ~/.bashrc

Copy the following line into the ~/.bashrc file and save it. If you don't know how to use the vim editor, please search online.

export PATH=/usr/local/cuda-12.4/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64:$LD_LIBRARY_PATH

or

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH


# 刷新当前终端的环境变量
source ~/.bashrc

# 验证CUDA是否安装成功
nvcc -V

If the image below appears, the installation was successful.

Install cuDNN (mostly deprecated, see below for apt and dnf installation methods for CuDNN)
  1. Select the appropriate cuDNN version for download based on the installed CUDA version. Note that registration and login are required here:

https://developer.nvidia.cn/rdp/cudnn-archive#a-collapse805-111

Since I am using CUDA 12.4, all versions marked with a red circle below are installable, and the newer the better. (The highest version on the website above is only v8.9.7, but there are even newer versions available — you can skip ahead to the apt and dnf installation methods below.)

The red one is common to all X86 architecture Linux systems, so I chose the red one.

The green one is Ubuntu for the X86 architecture. If you are using Ubuntu and your CPU is based on the X86 architecture, you can choose to download it.

The blue one is Ubuntu for the arm64 (aarch64) architecture. If you are using Ubuntu and your CPU is arm64 (aarch64), you can choose to download it.

Here I choose the most universal method for all Linux X86_64:

Downloaded.

  1. Install cuDNN

Find the directory where this file is located, open a terminal, and cd into that directory.

Extract the file and copy it to the corresponding location to complete the installation.


# 解压cuDNN文件
tar -xvf ./cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz

# cd进文件夹
cd ./cudnn-linux-x86_64-8.9.7.29_cuda12-archive

# 复制cuDNN文件到CUDA目录
sudo cp include/cudnn*    /usr/local/cuda/include
sudo cp lib/libcudnn*    /usr/local/cuda/lib64

# 对比一下有没有缺文件
ls /usr/local/cuda/include/cudnn*
ls /usr/local/cuda/lib64/libcudnn*

# 给予权限
sudo chmod a+r /usr/local/cuda/include/cudnn*
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
  1. Check if the installation was successful.

# 检查cuDNN版本命令
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

If the image below appears, the installation was successful.

  1. soft link

# 运行 ldconfig 以更新库缓存:(如果运行 ldconfig 后没有出现任何错误,说明配置已经完成。)
sudo ldconfig

If the following prompt appears, a symbolic link is required (if the following prompt does not appear, nothing needs to be done).

ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn.so.8 is not a symbolic link  
ldconfig: /usr/local/cuda-12.4/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 is not a symbolic link

Run the command below.


# cd进入CUDA路径
cd /usr/local/cuda/targets/x86_64-linux/lib

 # 查看本路径下的需要软链接的文件名
 ls

As shown in the image above, I need to create soft links for libcudnn_xxx_xxxxx.so.8.9.7, libcudnn_xxx_xxxxx.so.8, and libcudnn_xxx_xxxxx.so.


# 创建符号链接。对于每个 .so.8 文件,需要创建一个指向该文件的符号链接,通常链接的名称是不包含 .8 的文件名。
sudo ln -sf libcudnn_cnn_train.so.8.9.7 libcudnn_cnn_train.so.8
sudo ln -sf libcudnn_adv_infer.so.8.9.7 libcudnn_adv_infer.so.8
sudo ln -sf libcudnn_adv_train.so.8.9.7 libcudnn_adv_train.so.8
sudo ln -sf libcudnn_cnn_infer.so.8.9.7 libcudnn_cnn_infer.so.8
sudo ln -sf libcudnn.so.8.9.7 libcudnn.so.8
sudo ln -sf libcudnn_ops_infer.so.8.9.7 libcudnn_ops_infer.so.8
sudo ln -sf libcudnn_ops_train.so.8.9.7 libcudnn_ops_train.so.8

# 运行 ldconfig 以更新库缓存:(如果运行 ldconfig 后没有出现任何提示,说明配置已经完成。)
sudo ldconfig

# 使用 ls -l 来确认符号链接是否创建成功:(再次确认链接)
ls -l /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_*.so*
音乐页