# Install *Module* for Different CUDA Environment (On Linux)
###### tags: `Linux` `tutorials`
```
##### check your original CUDA version firt #####
(base) username@username:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243
```
## I. Install Specific CUDA Version
Eg. take CUDA11.6 for example
* Got to [here](https://developer.nvidia.com/cuda-11-6-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_local), follow the installation instruction and change the last line to:
```
sudo apt-get install -y cuda-11.6
```
* CUDA will be install in: `/usr/local`
## II. Install *Module*
Eg. take CUDA11.6 for example
#### install environment-modules
```
sudo apt-get install environment-modules
```
#### create cuda modulefile
```
cd /usr/share/modules/modulefiles
mkdir cuda
cd cuda
sudo vim 11.6 #the cuda version you installed
```
#### in file *11.6*, paste below
```
#%Module1.0#####################################################################
proc ModuleHelp {} {
puts stderr "\t Adds NVIDIA CUDA Toolkit 11.6 to your environment variables"
}
module-whatis "adds NVIDIA CUDA Toolkit 11.6 to your environment variables"
setenv CUDA_HOME /usr/local/cuda-11.6
prepend-path PATH /usr/local/cuda-11.6/bin
prepend-path LD_LIBRARY_PTH /usr/local/cuda-11.6/lib64
```
#### Add the environment variable to `.bashrc`
```
# >>> module initialize >>>
if [ -f /usr/share/modules/init/bash ]; then
source /usr/share/modules/init/bash
fi
# <<< module initialize >>>
```
#### Run below in your home directory
```
cd ~
source .bashrc
```
#### You can use *Module* right now !!d
```
##### test below #####
(base) username@username:~$ module avail
------------------------ /usr/share/modules/modulefiles ------------------------
cuda/11.6 dot module-git module-info modules null use.own
(base) username@username:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0
```
## III. *Module* instructions
```
module avail
module load cuda/{version}
module unload cuda/{version}
module list
```
## IV. Note
If you want to install another version of CUDA, just follow **step I**, and create corresponding module file.
## V. Reference
*For more details, check the refernce.*
https://blog.csdn.net/m0_37201243/article/details/129632603