CUDA
Go to the Nvidia CUDA Tools official website to select the corresponding architecture and version to download CUDA
Take the following architecture and version as an example:
View graphics card driver
nvidia-smi
If the graphics card driver has already been installed (such as the Driver Version: 535.54.03 prompted here), then when selecting the components to be installed during the CUDA installation process, there is no need to check the installation driver.
Download and install CUDA
Download and install CUDA according to the download and installation commands corresponding to the operating system and architecture you just selected.
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run
Uninstall CUDA
A common situation is that when using Pytorch, there is a requirement for the CUDA version. Even in the Conda environment, there are occasional problems, so downgrade to CUDA11.8 corresponding to Pytorch2.0.1, assuming that the cuda version is 12.1 at this time
cd /usr/local/cuda-12.1/bin/
sudo ./cuda-uninstaller
sudo rm -rf /usr/local/cuda-12.1
Conda
Download Anaconda
Go to the Anaconda official download page to download the installation script.
Install Anaconda
empower
sudo chmod +x Anaconda3-2023.07-2-Linux-x86_64.sh
Execute script
./Anaconda3-2023.07-2-Linux-x86_64.sh
Note: If you do not want to start the command line terminal to automatically open conda base, remember not to set the base environment to automatically activate during installation.
If you accidentally set the automatic activation of base,
you can enter the following command
conda config --set auto_activate_base false
Check if the installation is complete
conda --version
create environment
conda create -n <env_name> python=3.7 -y
Delete environment
conda remove -n <env_name> --all
activate environment
conda activate <env_name>
Exit environment
conda deactivate <env_name>
install software
Use installation in the corresponding virtual environment
conda install <app_name>
Specify channel installation
conda install -c conda-forge package-name
View conda information
conda info
uninstall software
Use uninstall in the corresponding virtual environment
conda uninstall <app_name>
Pytorch
Go to the Pytorch official website to select the appropriate Pytorch version and download it
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
Check if the installation is successful
conda list | grep pytorch
(base) hermanye@hermanye:~$ python
Python 3.11.4 (main, Jul 5 2023, 14:15:25) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5, 3)
>>> print(x)
tensor([[0.5421, 0.5950, 0.3337],
[0.8443, 0.2287, 0.5316],
[0.0301, 0.0151, 0.3522],
[0.3456, 0.5901, 0.5970],
[0.6271, 0.8065, 0.7645]])
>>>