# 安裝 nvidia 顯卡驅動遇到 The CC version check failed 解決方法 ###### tags: `Linux` ## Problem ```linux= The CC version check failed: The kernel was built with gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12), but the current compiler version is cc(Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010. ``` ## Solution 1. 移除舊驅動 ```linux= sudo apt purge nvidia* ``` 2. 先確認 compile 此 kernel 版本用的 C compiler版本是多少,ex 5.8.0 是由 gcc 9.3 compile 的,可由 ``cc -v`` 得知現在版本 ```linux= cc -v # ... # gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) ``` 4. 確認安裝好此版本的 gcc ```linux= # 查看 gcc 所在位置 which gcc-9 # /usr/local/bin/gcc-9 ``` 4. 將舊的 gcc link 移除 ```linux= which gcc # /usr/local/bin/gcc rm /usr/local/bin/gcc ``` 5. 將 gcc-9 soft link 到 gcc ```linux= ln -s /usr/bin/gcc-9 /usr/local/bin/gcc ``` 6. 查看 cc 的位置 ```linux= which cc # /usr/bin/cc ``` 7. 依序看最後link到哪 ```linux= root@erichuLinux:~# ls -al /usr/bin/cc lrwxrwxrwx 1 root root 20 7月 29 2021 /usr/bin/cc -> /etc/alternatives/cc root@erichuLinux:~# ls -al /etc/alternatives/cc lrwxrwxrwx 1 root root 12 4月 20 16:50 /etc/alternatives/cc -> /usr/bin/gcc root@erichuLinux:~# ls -al /usr/bin/gcc lrwxrwxrwx 1 root root 21 4月 20 16:51 /usr/bin/gcc -> /etc/alternatives/gcc root@erichuLinux:~# ls -al /etc/alternatives/gcc lrwxrwxrwx 1 root root 14 4月 20 19:51 /etc/alternatives/gcc -> /usr/bin/gcc-9 ``` 8. 若最後link到不同版本的gcc,用```update-alternatives --query gcc``` 看現在共有哪些版本可以切換 ```linux= Name: gcc Link: /usr/bin/gcc Status: manual Best: /usr/bin/gcc-9 Value: /usr/bin/gcc-9 Alternative: /usr/bin/g++-11 Priority: 10 Alternative: /usr/bin/gcc-11 Priority: 10 Alternative: /usr/bin/gcc-9 Priority: 10 ``` 10. 若沒有得切換版本,用以下指令加入 ```linux= update-alternatives --install /usr/local/bin/gcc gcc /usr/bin/gcc-9 10 update-alternatives --install [which gcc] gcc [which gcc-9] [priority] update-alternatives --set gcc /usr/bin/gcc-9 ``` 11. 切換 gcc version ```linux= sudo update-alternatives --config gcc ``` 12. 就可以手動安裝從 nvidia 官網下載的驅動了 ```linux= sudo ./NVIDIA-Linux-*.run ``` ## Reference https://www.if-not-true-then-false.com/2021/debian-ubuntu-linux-mint-nvidia-guide/ https://blog.csdn.net/hizengbiao/article/details/103698560 https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu