Cuda10.1 installation with gcc7 errors

I want to install cuda10.1 and cudnn7 along with gcc7 for a project on ubuntu22.04
How can i do this without breaking cuda and libcublas.
The command sudo apt install cuda10.1 downloads gcc11.4 and i need help in downgrading it to 7.