# 在ubuntu安裝神經網路環境 ## 安裝版本 nvidia driver: 525 -> 530 CUDA: 12.1 cuDNN: 8.8.1 ## 每次都會先做的事 `sudo apt update && sudo apt upgrade -y` ## 移除所有舊版本 `sudo apt purge *nvidia*` ## 顯卡驅動 1. 查詢驅動版本 `ubuntu-drivers list` 選擇一個要安裝的版本 如果沒有特別要求 選最新的(數字最大的)就好 2. 安裝驅動 `sudo apt install nvidia-driver-xxx` 安裝完CUDA後版本可能會變,但不用去管 例如我原本安裝525 安裝完CUDA後自動變成530 這甚至不在`ubuntu-drivers list`顯示的列表裡面 3. 重新開機 4. 檢查驅動 `nvidia-smi` 應該會顯示以下結果 ![](https://i.imgur.com/WSdMhlN.png) 細節目前不重要 能顯示出這個表就行 ## CUDA 1. 安裝CUDA [https://developer.nvidia.com/cuda-downloads](https://developer.nvidia.com/cuda-downloads) 我只用過deb(local),沒用過另外兩個 2. 重新開機 3. 檢查CUDA `nvcc -V` 應該會顯示以下結果 ![](https://i.imgur.com/JeNAPi6.png) 如果顯示以下結果 ![](https://i.imgur.com/6kaQoQf.png) 千萬不能安裝`nvidia-cuda-toolkit` (如果不小心安裝了... 我建議你從`sudo apt purge *nvidia*`那步開始重來) 會顯示說找不到`nvcc`是因為`nvcc`不在路徑中 以我的安裝來說,`nvcc`的路徑是`/usr/local/cuda-12.1/bin/nvcc` 將以下字串加入殼層設定檔(如`~/.bachrc`)的尾端 `export PATH=/usr/local/cuda-12.1/bin/${PATH:+:${PATH}}` 實際路徑依據安裝版本而定 ## cuDNN 1. 下載cuDNN [https://developer.nvidia.com/rdp/cudnn-download](https://developer.nvidia.com/rdp/cudnn-download) 2. 安裝並檢查cuDNN [https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html) ###### tags: `linux` `ubuntu` `nvidia` `driver` `cuda` `cudnn` `python` `pytorch`