{"id":24503964,"url":"https://github.com/kabir5296/deep-learning-setup-for-ubuntu-guide","last_synced_at":"2025-03-15T08:24:21.394Z","repository":{"id":272419652,"uuid":"916529696","full_name":"Kabir5296/Deep-Learning-Setup-for-Ubuntu-Guide","owner":"Kabir5296","description":"CUDA, CuDNN, NVIDIA Driver, and PyTorch Installation for Ubuntu","archived":false,"fork":false,"pushed_at":"2025-02-27T11:45:39.000Z","size":97,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T16:16:29.946Z","etag":null,"topics":["cuda","cudnn","deeplearning","nlp","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kabir5296.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-14T09:23:23.000Z","updated_at":"2025-02-27T11:45:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9f3acb7-1336-400d-b53a-f9d9e14e4d3e","html_url":"https://github.com/Kabir5296/Deep-Learning-Setup-for-Ubuntu-Guide","commit_stats":null,"previous_names":["kabir5296/deep-learning-setup-for-ubuntu-guide"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kabir5296%2FDeep-Learning-Setup-for-Ubuntu-Guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kabir5296%2FDeep-Learning-Setup-for-Ubuntu-Guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kabir5296%2FDeep-Learning-Setup-for-Ubuntu-Guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kabir5296%2FDeep-Learning-Setup-for-Ubuntu-Guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kabir5296","download_url":"https://codeload.github.com/Kabir5296/Deep-Learning-Setup-for-Ubuntu-Guide/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243704265,"owners_count":20334122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","cudnn","deeplearning","nlp","python","pytorch"],"created_at":"2025-01-21T23:19:16.186Z","updated_at":"2025-03-15T08:24:21.361Z","avatar_url":"https://github.com/Kabir5296.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Ubuntu Deep Learning System Setup Guide: \n### CUDA, CuDNN, NVIDIA Driver, and PyTorch Installation Guide\nby **A F M Mahfuzul Kabir**, \\\nMachine Learning Engineer, \\\nACI Limited \\\n\u003ca href=\"mahfuzulkabir.com\"\u003emahfuzulkabir.com\u003c/a\u003e\n\n## How to use this document:\nFor the simplest form of use, run the 'one-click-installer.sh' bash file. This will install the default nvidia driver 550 version, CUDA 12.8 (currently latest), and CuDNN 9.\n```\nchmod u+x ./one-click-installer.sh\n./one-click-installer.sh\n```\nHowever, this file is not guranteed to be error-free, since it depends on your system and hardware. So, it's better to go over the following documents and try to install everything manually.\n\n## Manual Installation - RECOMMENDED\nThis document has four parts.\n1. NVIDIA Driver Installation.\n2. CUDA Installation.\n3. CuDNN Installation.\n4. Install Python, PyTorch, and necessary libraries.\n\nEverything is centred around Ubuntu, because, lets agree that we developers don't feel comfortable with Windows and Mac is just a bit too expensive for us. :')\n\nOnce you're done setting up Ubuntu on your local or cloud server, follow the following processes. You can find many systems online automatically set up with all driver libraries. But, it's always better to do this on your own so you don't face unexpected errors.\n\n**READ THE DOCUMENT CAREFULLY BEFORE RUNNING ANY COMMAND**\n\n## First Install the NVIDIA Driver.\nFirst of all, if you installed Ubuntu with third party drivers enabled, you can skip this step. Only check the existing NVIDIA version for your device.\n\nCheck if GPU is compatible and if it has previously installed NVIDIA\n```\n### to verify your gpu is cuda enable check\nlspci | grep -i nvidia\n\n## check previously installed NVIDIA version\nmodinfo nvidia | grep ^version\n```\n\nYou can check for recommended versions of NVIDIA driver with the following command.\n```\nubuntu-drivers devices\n```\n\nIf you have a previously installed version of NVIDIA and need to uninstall it (often specific CUDA versions require specific versions of NVIDIA drivers, and your need might require you to reinstall NVIDIA), remove it with the followig code:\n```\n# Remove existing installations of NVIDIA driver\n\nsudo apt purge nvidia* -y\nsudo apt remove nvidia-* -y\nsudo rm /etc/apt/sources.list.d/cuda*\nsudo apt autoremove -y \u0026\u0026 sudo apt autoclean -y\n```\n\nInstall NVIDIA driver. In the place of 550, replace your desired version\n```\n## install NVIDIA driver (specific version). Here, I'm installing it for 550\nsudo apt update \u0026\u0026 sudo apt upgrade -y\nsudo apt install gcc\nsudo add-apt-repository ppa:graphics-drivers/ppa\nsudo apt update\nsudo apt install libnvidia-common-550 libnvidia-gl-550 nvidia-driver-550 -y\n```\n\nIn the place of 550, replace if you need other versions. Reboot and check if the NVIDIA installation is done. Run ```nvidia-smi``` to check. It should show you device information as well as versions.\n\n## CUDA Installation\nPerhaps the most confusing and difficult part of the installation process. Follow carefully.\n\nThe best way to install CUDA without any problem is from the official website. The webpage is different for each versions. Like, for CUDA 12.4 the webpage is: \u003ca href = \"https://developer.nvidia.com/cuda-12-4-0-download-archive?target_os=Linux\"\u003e[Link]\u003c/a\u003e and for the latest CUDA (currently 12.6), the webpage is: \u003ca href = \"https://developer.nvidia.com/cuda-downloads?target_os=Linux\"\u003e[Link]\u003c/a\u003e.\n\nYou have to carefully select which CUDA version you need. Many libraries or models or architectures require specific versions of CUDA. Make sure you're using the most compatible version according to your need. \n\nIf you don't have any specific need, run ```nvidia-smi``` and look for ```CUDA Version:``` on top right. You can install the version shown here. For me, it's **12.4**, so I will show you installation for this.\n\nOnce you know the CUDA version you need, simply search Google to find the webpage as needed. You should find a webpage like the image below. Select the OS, arch, and distribution information.\n\n\u003cimg src=\"./asset/CudaPage.png\" alt=\"cuda\" width=\"100%\"\u003e\n\nThen, run the commands shown in the following parts of the webpage. For me the commands are given below:\n\n```\nwget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin\n\nsudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600\n\nwget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb\n\nsudo dpkg -i cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb\n\nsudo cp /var/cuda-repo-ubuntu2204-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/\n\nsudo apt-get update\n\nsudo apt-get -y install cuda-toolkit-12-4\n```\n\nNotice, the distribution ad architecture info is embedded in the links as ```ubuntu2201``` and ```x86_64```. The cuda version is in the third command as ```12.4.0```, and the driver version is also stated as ```550.54.14```. Make sure these align with the driver and CUDA versions you extracted before. Specially, the driver version.\n\nNote: My driver version was ```550.120``` and I installed ```550.54.14```, it didn't cause a problem. However, I did face problem with ```535```. So, make sure at least the first part of your version is aligned. You can modify the code as needed for your own implementation, but the best way is to follow the official instructions.\n\nOnce you have done installing, run the following codes to add CUDA to your system environment.\n```\necho 'export PATH=\"/usr/local/cuda-12.4/bin${PATH:+:${PATH}}\"' \u003e\u003e ~/.bashrc\necho 'export LD_LIBRARY_PATH=\"/usr/local/cuda-12.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}\"' \u003e\u003e ~/.bashrc\nsource ~/.bashrc\nsudo ldconfig\n```\nIn the place of ```cuda-12.4```, replace with your version of cuda.\n\nRun ```nvcc -V``` to confirm installation. It should show you the CUDA version installed. You should see something like this:\n```\nnvcc: NVIDIA (R) Cuda compiler driver\nCopyright (c) 2005-2024 NVIDIA Corporation\nBuilt on Tue_Feb_27_16:19:38_PST_2024\nCuda compilation tools, release 12.4, V12.4.99\nBuild cuda_12.4.r12.4/compiler.33961263_0\n```\n\nCongratulations, you are done installing CUDA.\n\n## CuDNN Intallation\nOnce you're done installing CUDA, you'll be needed to install CuDNN. Just like CUDA, follow the official instructions. You can follow this link for the instructions: \u003ca href = \"https://developer.nvidia.com/cudnn-downloads?target_os=Linux\"\u003e[Link]\u003c/a\u003e.\n\nOr run the code below. Make sure you adjust the OS, distribution, and architecture as before.\n\n```\nwget https://developer.download.nvidia.com/compute/cudnn/9.6.0/local_installers/cudnn-local-repo-ubuntu2204-9.6.0_1.0-1_amd64.deb\n\nsudo dpkg -i cudnn-local-repo-ubuntu2204-9.6.0_1.0-1_amd64.deb\n\nsudo cp /var/cudnn-local-repo-ubuntu2204-9.6.0/cudnn-*-keyring.gpg /usr/share/keyrings/\n\nsudo apt-get update\n```\n\nAfter these steps, run either of the following commands to install CuDNN for CUDA 11 or CUDA 12. These days, most systems require CUDA 12, but it depends on which CUDA version you installed previously.\n\n```\n# For CUDA 11:\nsudo apt-get -y install cudnn-cuda-11\n# For CUDA 12:\nsudo apt-get -y install cudnn-cuda-12\n```\n\nCheck installation with ```cat /usr/include/x86_64-linux-gnu/cudnn_version_v9.h ```.\n\n## Python, PyTorch Installation\nNext, install Python. Ubuntu always have a specific Python version preinstalled in the system, but you might need other versions. For this, we use the ```deadsnake``` repository to install Python. Add this repository to your system first:\n```\nsudo apt update\nsudo add-apt-repository ppa:deadsnakes/ppa\n```\nNow, you can simply install your desired version of Python. Make sure to install ```python-dev``` and ```python-venv``` as well, since you'll deffinitely need them for development.\n```\nsudo apt-get install python3.9 python3.9-dev python3.9-venv\n```\nIn place of ```3.9``` replace your desired Python version. You can create new Python virtual environment with ```python3.9 -m venv my_venv``` and activate it ```source my_venv/bin/activate```. Make sure to activate the environment before installing torch.\n\nOnce you're done installing all prequisites (check all versions to see if working), you can install PyTorch and other necessary libraries. Follow the guide in this link: \u003ca href=\"https://pytorch.org/get-started/locally/\"\u003e[Link]\u003c/a\u003e. Make sure to select proper version of CUDA according to your installation. For example, CUDA 12.1 download link is:\n\n```\npip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\n```\nwhereas CUDA 11.8 is:\n```\npip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118\n```\nThe links are same except for the ```cu\u003cversion\u003e``` part at last. Make sure to use the CUDA version your system has, or PyTorch will install but fail to run.\n\nIf you have the latest CUDA version, simply run ```pip3 install torch torchvision torchaudio```.\n\n### That's it. You're done and ready for Deep Learning developments with NVIDIA and CUDA.\n\n## Don't forget to leave a **STAR** if you found this helpful.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabir5296%2Fdeep-learning-setup-for-ubuntu-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkabir5296%2Fdeep-learning-setup-for-ubuntu-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabir5296%2Fdeep-learning-setup-for-ubuntu-guide/lists"}