1、先确定显卡型号,这里是GeForce RTX 4060
lshw -C display
#或者可尝试 lspci -v |grep VGA
*-display UNCLAIMED
description: VGA compatible controller
product: AD107 [GeForce RTX 4060]
vendor: NVIDIA Corporation
physical id: 0
.......
2、安装前需要先禁用nouveau并重启(安装Nvidia显卡的官方驱动和系统自带的nouveau驱动冲突,两者只能选其一,nouveau属于第三方通用驱动)
#查看是否加载nouveau
lsmod |grep nouveau
#禁用nouveau
vi /etc/modprobe.d/blacklist-nouveau.conf
#加入如下两行
blacklist nouveau
options nouveau modset=0
#更新,并重启,这里也可以使用 update-initramfs -u 重建initramfs
dracut --force
reboot
#再次查看是否禁用成功。若没有输出,则表示禁用成功。
lsmod |grep nouveau
3、安装基础依赖包
yum install -y gcc gcc-c++ kernel-devel-$(uname -r) kernel-headers-$(uname -r)
yum install -y make vulkan-loader
4、安装显卡驱动(下载地址:https://www.nvidia.cn/geforce/drivers/)
运行驱动包
[root@localhost ~]# sh NVIDIA-Linux-x86_64-570.133.07.run
Verifying archive integrity... OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 570.133.07Extraction failed.
Signal caught, cleaning up
这里解压提取失败,因为安装Anolis时使用了最小安装,很多软件没有安装,运行驱动包时需使用tar,但系统没有找到tar,因此直接报Extraction failed ,解决方法:安装tar(yum install -y tar)安装好tar后,再次运行安装包顺利进入安装界面,一般选NVIDIA Proprietary(性能和兼容性更好但闭源)(MIT/GPL开源,性能稍弱)
安装期间的交互与选项
WARNING: nvidia-installer was forced to guess the X library path '/usr/lib64' and X module path'/usr/lib64/xorg/modules'; these paths were not queryable from the system. If X fails to find the NVIDIA X driver module, please install the `pkg-config` utility and the X.Org SDK/development package for yourdistribution and reinstall the driver
选OK
Install NVIDIA's 32-bit compatibility libraries?
选no
The initramfs will likely need to be rebuilt due to the following condition(s):
* Nouveau is present in the initramfs.
Would you like to rebuild the initramfs?
选Rebuild initramfs
Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up.
选择yes
最后提示:
Your X configuration file has been successfully updated. Installation of the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version: 570.133.07) is now complete.
代表安装完成。
验证是否有加载nvidia驱动
[root@localhost ~]# lsmod | grep nvidia
nvidia_drm 94208 0
nvidia_modeset 1531904 1 nvidia_drm
nvidia 89886720 1 nvidia_modeset
drm_kms_helper 262144 1 nvidia_drm
drm 569344 4 drm_kms_helper,nvidia,nvidia_drm
i2c_core 98304 5 drm_kms_helper,nvidia,i2c_smbus,i2c_i801,drm
用nvidia-smi命令查看GPU信息
查看显卡驱动driver是否是nvidia
lshw -c video | grep configuration
5、安装CUDA
用nvidia-smi 命令查看驱动支持的cuda最高版本
前往官网下载CUDA:https://developer.nvidia.com/cuda-toolkit-archive
打开页面后,可以使用页面下方命令下载和安装
wget https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_570.124.06_linux.runsudo
sh cuda_12.8.1_570.124.06_linux.run
安装时原因第4步已经安装驱动,所以这里不需要再重新安装驱动(这里版本旧一点)
安装完成
把CUDA加入到个人PATH环境变量
vi ~/.bashrc
export PATH=/usr/local/cuda-12.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-12.8
source ~/.bashrc
检查是否安装了CUDA
ls -l /usr/local | grep cuda
使用命令 nvcc -V 输出cuda版本号则安装成功。
#成功输出
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Fri_Feb_21_20:23:50_PST_2025
Cuda compilation tools, release 12.8, V12.8.93
Build cuda_12.8.r12.8/compiler.35583870_0
6、安装cuDNN(需要注册nvidia账号)
下载网址:https://developer.nvidia.com/rdp/cudnn-archive
上传压缩包到服务器后,解压缩
tar -xvf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz
cd cudnn-linux-x86_64-8.9.7.29_cuda12-archive/
cp lib/* /usr/local/cuda-12.8/lib64/
cp include/* /usr/local/cuda-12.8/include/
chmod a+r /usr/local/cuda-12.8/lib64/*
chmod a+r /usr/local/cuda-12.8/include/*
验证cuDNN是否安装成功
cat /usr/local/cuda-12.8/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
进入/usr/local/cuda-12.8/extras/demo_suite/* 下有一些测试样例程序
deviceQuery会输出CUDA的相关信息,如纹理内存、常量内存、共享内存等
./deviceQuery
./deviceQuery Starting...
CUDA Device Query (Runtime API)
Detected 1 CUDA Capable device(s)
Device 0: "NVIDIA GeForce RTX 4060"
CUDA Driver Version / Runtime Version 12.8 / 12.8
CUDA Capability Major/Minor version number: 8.9
Total amount of global memory: 7814 MBytes (8193835008 bytes)
MapSMtoCores for SM 8.9 is undefined. Default to use 128 Cores/SM
MapSMtoCores for SM 8.9 is undefined. Default to use 128 Cores/SM
(24) Multiprocessors, (128) CUDA Cores/MP: 3072 CUDA Cores
GPU Max Clock rate: 2550 MHz (2.55 GHz)
Memory Clock rate: 8501 Mhz
Memory Bus Width: 128-bit
L2 Cache Size: 25165824 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1536
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 12.8, CUDA Runtime Version = 12.8, NumDevs = 1, Device0 = NVIDIA GeForce RTX 4060
Result = PASS
驱动到此已经安装完毕,下一步就可以安装大模型了
参考文章:
https://blog.csdn.net/u014073556/article/details/145924098
https://openanolis.cn/sig/AI_SIG/doc/721423765456666646