Chieh997
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Ubuntu24.04/22.04重灌筆記:GPU安裝與深度學習 ###### tags: `Tutorial`, `Ubuntu`, `VScode`, `python` 目錄: + [重灌Ubuntu](#ubuntu) + [CUDA安裝](#cuda) + [Nvidia driver](#nvidia) + [CUDA Toolkit](#toolkit) + [cudnn](#cudnn) + [建立虛擬環境](#virtualenv) + [使用方法](#venv) + [終端機管理工具: tmux](#tmux) + [下載 google drive 檔案: gdown](#gdown) + [安裝python 3.9](#py39) 其他筆記: + [VScode 使用 SSH 進行遠端程式開發](https://hackmd.io/@Chieh997/VScodeSSH) + [深度學習python套件安裝](https://hackmd.io/@Chieh997/deeppython): Install Pytorch, Tensorflow, Pyspark + [R in Ubuntu22.04](https://hackmd.io/@Chieh997/ubuntur): Install R and use with Jupyter Notebook and VScode --- <a id='ubuntu'></a> ## 重灌Ubuntu + [Ubuntu 是什麼?如何透過 USB 安裝 Ubuntu 作業系統?完整教學指南](https://adersaytech.com/practical-software/ubuntu-install-tutorial.html) ### 製作重灌隨身碟 1. 前往[Rufus官方網站](https://rufus.ie/zh_TW/)並下載Rufus軟體 ![Rufus.exe](https://i.imgur.com/pDYeHo7.png) 2. 前往[Ubuntu官方網站](https://ubuntu.com/download/desktop)下載桌面版的安裝檔(ISO) 3. 使用Rufus及安裝檔建立重灌用開機隨身碟 ![Rufus.iso](https://adersaytech.com/wp-content/uploads/2021/08/Rufus-make-ubuntu.webp =400x) ### 進入開機選單選擇USB開機 - Long press `Esc`, `F2`, `Del` or other possible keys when press the power bottom to go to BIOS or boot menu. - Check the key based on your motherboard's brand --- <a id='cuda'></a> ## CUDA安裝 + [Ubuntu 20.04中安裝nvidia-driver-460版 & CUDA-11.4.2版 & cuDNN](https://medium.com/@scofield44165/ubuntu-20-04%E4%B8%AD%E5%AE%89%E8%A3%9Dnvidia-driver-cuda-11-4-2%E7%89%88-cudnn-install-nvidia-driver-460-cuda-11-4-2-cudnn-6569ab816cc5) + [Ubuntu 安裝 CUDA cuDNN pytorch tensorflow mxnet](https://mikethreeacer.medium.com/ubuntu-18-04-%E5%AE%89%E8%A3%9D-cuda-cudnn-anaconda-pytorch-1f170b3326a4#1b0a) + [Ubuntu16.04安装NVIDIA驱动+CUDA9.0+cuDNN7.0](https://blog.csdn.net/mtllyb/article/details/79505012) + [Ubuntu 22.04 for Deep Learning](https://gist.github.com/amir-saniyan/b3d8e06145a8569c0d0e030af6d60bea) ### 確認GPU資訊 ```bash sudo lshw -numeric -C display ``` <a id='nvidia'></a> ### Install Nvidia Driver 如果在有網路的情況下安裝ubuntu且同意third-party程式一同安裝(include nvidia dirver),可先直接確認是否有安裝成功。成功安裝可直接進入cuda-toolkit安裝。 ``` nvidia-smi ``` 1. 列出支援的GPU driver版本 ```bash=0 ubuntu-drivers devices # or ubuntu-drivers list ``` 2. 安裝nvidia-driver並重新啟動 ```bash=+ sudo apt-get update sudo apt upgrade sudo apt install nvidia-driver-{VERSION_NUMBER} sudo reboot ``` 3. 檢查nvidia driver版本 ```bash=+ nvidia-smi ``` - [清除既有nvidia driver和ppa](https://forums.developer.nvidia.com/t/newly-installed-drivers-are-not-found-when-nvidia-smi-is-called/82686/6) ```bash=0 sudo apt-get remove --purge '^nvidia-.*' sudo apt-get --purge remove "*cublas*" "cuda*" sudo apt-get --purge remove "*nvidia*" sudo add-apt-repository --remove ppa:graphics-drivers/ppa sudo rm /etc/X11/xorg.conf sudo apt autoremove sudo reboot ``` <a id='toolkit'></a> ### Install CUDA-Toolkit + [NVIDIA CUDA Installation Guide for Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu-installation) 1. 依序執行官方網站中的指令,local或network都可以 ![](https://i.imgur.com/e9iBufK.png) + Install [Latest CUDA](https://developer.nvidia.com/cuda-downloads) - 推薦使用network下載,較容易成功。 ```bash=0 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb sudo dpkg -i cuda-keyring_1.0-1_all.deb sudo apt-get update sudo apt-get -y install cuda ``` + Install Older CUDA (e.g. [11.7](https://developer.nvidia.com/cuda-11-7-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_network)) + 建議用deb(local)安裝,須在最後一行指定CUDA版本 + 安裝出現錯誤(`E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.`)的[解法](https://blog.csdn.net/weixin_42156097/article/details/103805063) ```bash=0 sudo apt-get install aptitude sudo aptitude install cuda sudo apt-get install cuda ``` 2. `.bashrc`設定環境並刷新terminal ```bash export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 export PATH=$PATH:/usr/local/cuda/bin ``` ```bash=+ source .bashrc ``` 3. 檢查CUDA版本 ```bash=+ nvcc -V ``` <a id='cudnn'></a> ### Install cuDNN #### Method 1: [Latest Version Download](https://developer.nvidia.com/cudnn-downloads) ```bash=1 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt-get update sudo apt-get -y install cudnn ``` #### Method 2: [cuDNN Package Manager Installation](https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#cudnn-package-manager-installation-overview) 1. Enable the repository ```bash=1 # ${OS} = debian11, ubuntu1804, ubuntu2004, or ubuntu2204 wget https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-${OS}.pin sudo mv cuda-${OS}.pin /etc/apt/preferences.d/cuda-repository-pin-600 sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/3bf863cc.pub sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/ /" sudo apt-get update ``` 2. Install the [cuDNN library](https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/) ```bash=+ # ${cudnn_version} = 8.{x}.0.* # ${cuda_version} = cuda11.{y} sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version} sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version} ``` + [How to verify CuDNN installation?](https://stackoverflow.com/questions/31326015/how-to-verify-cudnn-installation) :::info Might not working for ubuntu 24.04 ::: ```bash=+ whereis cudnn_version.h CUDNN_H_PATH=$(whereis cudnn_version.h) cat ${CUDNN_H_PATH} | grep CUDNN_MAJOR -A 2 ``` The result should be look like the following, which means the version is `{X}.{Y}.0` ```C #define CUDNN_MAJOR {X} #define CUDNN_MINOR {Y} #define CUDNN_PATCHLEVEL 0 ``` --- <a id='virtualenv'></a> ## 建立虛擬環境 ### [導出舊環境](https://stackoverflow.com/questions/14684968/how-to-export-virtualenv) 先進入舊環境,使用下列指令將需要用到的package導出至`requirements.txt` ```bash pip freeze > requirements.txt ``` ### 安裝Virtualenv與Virtualenvwrapper #### [[2025 Version] For Ubuntu 24.04 & Python 3.12](https://techbend.hashnode.dev/python312-upgrade-setting-up-virtualenvwrapper) Python 3.12阻止一般使用者在主環境下使用pip安裝,所以要先在虛擬環境下安裝virtualenvwrapper。 1. 更新系統安裝包 ```bash=0 sudo apt-get update sudo apt-get upgrade ``` 2. 安裝pip與Virtualenv ```bash=+ sudo apt-get install python3-pip sudo apt-get install virtualenv ``` 3. 建立虛擬環境**venv**,並在該環境下安裝Virtualenvwrapper ```bash+= # 建立並啟用環境venv virtualenv venv source ./venv/bin/activate # 在venv下安裝virtualenvwrapper pip install virtualenvwrapper ``` 4. 在啟動檔`.bashrc`或`.zshrc`中設定路徑與要求 + `WORKON_HOME`: 使用wrapper建立的環境一般會在 `$HOME/.virtualenvs` + virtualenvwrapper本體相關的路徑會在先前用virtualenv直接建立的**venv**路徑底下: `$HOME/venv/bin/` ```bash # PATH related to virtualenvwrapper workon export WORKON_HOME=$HOME/.virtualenvs # PATH related to virtualenvwrapper itself export VIRTUALENVWRAPPER_PYTHON=$HOME/venv/bin/python export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/venv/bin/virtualenv source $HOME/venv/bin/virtualenvwrapper.sh # Add venv as part of PATH export PATH="$HOME/venv/bin:$PATH" ``` #### For Python 3.10 1. 更新系統安裝包 ```bash=0 sudo apt-get update sudo apt-get upgrade ``` 2. 安裝pip ```bash=+ sudo apt-get install python3-pip ``` 3. 安裝Virtualenv與Virtualenvwrapper ```bash=+ sudo apt-get install virtualenv pip install virtualenvwrapper ``` 4. Virtualenvwrapper相關設定 + 在啟動檔`.bashrc`中設定路徑與要求 ```bash # {path/to/python}可以用`which python`來查詢 export WORKON_HOME={path/to/env} export VIRTUALENVWRAPPER_PYTHON={path/to/python} # export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # export WORKON_HOME=$HOME/.virtualenvs # export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv # 依據安裝位置嘗試下列其中一行指令即可 source ~/.local/bin/virtualenvwrapper.sh # source /usr/local/bin/virtualenvwrapper.sh ``` + 執行啟動檔 ```bash source .bashrc ``` <a id='venv'></a> ### Virtualenv使用方法 + 常用指令 ```bash # 建立環境 virtualenv {env_name} # 啟用環境 source ./{env_name}/bin/activate # 離開環境 deactivate ``` ### Virtualenvwrapper使用方法 + 常用指令 ```bash # 查詢環境 lsvirtualenv # 建立環境 mkvirtualenv -p {python3.X} {venv_name} # 刪除環境 rmvirtualenv {venv_name} # 使用環境 workon {venv_name} # 離開環境 deactivate ``` ### 重新安裝套件 ```bash pip install -r {path/to/requirements.txt} ``` #### Reference + [Ubuntu 環境下安裝pip & python3](http://python-learnnotebook.blogspot.com/2018/10/ubuntu-pip-python3.html) + [Python3 - Virtualenv & Virtualenvwrapper 拯救骯髒的套件環境](https://medium.com/@minecola/python3-%E6%8B%AF%E6%95%91%E9%AA%AF%E9%AB%92%E7%92%B0%E5%A2%83%E5%A4%A7%E4%BD%9C%E6%88%B0-with-virtualenv-4b398142463d) + [Using different versions of python with virtualenvwrapper - StackOverflow](https://stackoverflow.com/questions/6401951/using-different-versions-of-python-with-virtualenvwrapper) <a id='tmux'></a> ## 終端機管理工具:tmux ```mermaid flowchart LR; A[user] subgraph Server B["server core"] t0[/"connect session"/] t1[/session 1/] t2[/session 2/] t3[/.../] t0 -.- B -.- t1 & t2 & t3 end A <===>|ssh| t0 %% A x---x B ``` 使用時機: 1. 可開啟多個terminal視窗(但對於VScode使用者較無影響)。 2. 若程式執行時間過長,避免ssh斷線後中斷運行,此工具可協助於背景運行程式,不受連線情形影響。 ### Install tmux ```bash=0 sudo apt install tmux ``` Pane, window, session 等的差別與使用可參考 [Linux tmux 終端機管理工具使用教學](https://blog.gtwang.org/linux/linux-tmux-terminal-multiplexer-tutorial/) ### [Cheat Sheet](https://tmuxcheatsheet.com) + session `tmux new -s {my_session}`: creat new session `tmux ls`: show all sessions `tmux a -t {my_session}`: attach to specific session `Ctrl`+`b` `$`: rename when attach `Ctrl`+`b` `d`: detach when attach `Ctrl`+`b` `x` `y`: kill when attach <a id='gdown'></a> ## 下載google drive檔案: gdown + Installation ```bash pip install gdown ``` If install in venv, add the following path to `.bashrc` or `.zshrc`. ```bath # Add venv as part of PATH export PATH="$HOME/venv/bin:$PATH" ``` + Download one file `{file_ID}` can get from shared link in form `https://drive.google.com/file/d/{file_ID}/view?usp=drive_link` ```bash gdown --id {file_id} ``` + Download entire folder `folder_share_link` form: `https://drive.google.com/drive/folders/{folder_ID}` ```bash gdown --folder {folder_share_link} ``` <a id='py39'></a> ## 安裝python3.9 1. 更新系統安裝包 ```bash=0 sudo apt update sudo apt install software-properties-common ``` 2. 安裝`deadsnakes` PPA ```bash=+ sudo add-apt-repository ppa:deadsnakes/ppa ``` 3. 安裝Python3.9 ```bash=+ sudo apt install python3.9 ``` 4. 如果出現`No module named 'distutils.util'`的錯誤,安裝對應版本的`distutils`(可能需要再運行`python3.9 get-pip.py`) ```bash=+ sudo apt install python3.{X}-distutils ``` #### Reference + [How to Install Python 3.9 on Ubuntu 22.04 using APT](https://linuxhint.com/install-python-ubuntu-22-04/) + [How to install pip for Python 3.9 on Ubuntu 20.04 - StackOverflow](https://stackoverflow.com/questions/65644782/how-to-install-pip-for-python-3-9-on-ubuntu-20-04)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully