First step:get to the official site to choose a deb-package to install.
Ubuntu18.04+cuda11.1 installation precautions
when you input nvcc
Second step:
1.sudo reboot
2.check whether your nvidia-smi still working
3.add nvcc to your path
export CUDA_HOME=/usr/local/cuda
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda/bin:$PATH
Reference
Record: Ubuntu18.04 installs cuda11.1_YOURSWEET's blog-CSDN blog_ubuntu18.04 installs cuda11
Install Nvidia driver and Cuda Toolkit on Ubuntu 18.04 - Programmer Sought