The error I see is this:
nvcc fatal : Unknown option ‘-generate-dependencies-with-compile’
[5/6] /bin/nvcc --generate-dependencies-with-compile --dependency-output 

Have you checked CUDA versions?
Also, here’s a script to install Detectron2 using Anaconda. I’ve used it on Windows 10 with RTX3070, I don’t see why it won’t work on Ubuntu:

  
      github.com
  
  
    markstrefford/running-detectron2-on-windows-wsl2-rtx30xx/blob/d6f31ba7d3728cda8e223c24aa64b43f81818cdf/detectron2-windows-conda.yml 7
name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3