Installation in WSL2 with Ubuntu20/22/24 and VS Code Debug

For Windows 11 users, I believe many friends will love this working environment just like I do. The overall installation and compilation configuration are quite simple, and it’s also very convenient to use VS Code to call gdb for debugging.

I shared this installation method a few years ago( Visualization in WSL2 ), and now I’m documenting it again.

  1. Configure WSL2

  2. Install Ubuntu from Microsoft Store

  3. System prerequisites and Geant4 installation(Only QT5 selected for visualiztion)

    1. prerequisites and support libraries installation

      sudo apt-get update
      
      sudo apt-get install build-essential cmake gdb libexpat-dev qt5-qmake qtbase5-dev qt5-qmake-bin qtbase5-dev-tools
      
    2. Geant4 build and installation

      tar -xf  geant4-v11.3.2.tar.gz (In your path e.g. ‘/mnt/f/ubuntu24/g4/’)
      
      mkdir g4_install
      
      mkdir g4_build
      
      cd g4_build
      
      cmake -DCMAKE_INSTALL_PREFIX=/mnt/f/ubuntu24/g4/g4_install -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_QT=ON  /mnt/f/ubuntu24/g4/geant4-v11.3.2
      
      make -j8
      
      make install
      
      vi ~/.bashrc
      
      source /mnt/f/ubuntu24/g4/g4_install/share/Geant4/geant4make/geant4make.sh
      
      source /mnt/f/ubuntu24/g4/g4_install/bin/geant4.sh
      
  4. VS Code configuration

      1\. In the WSL2 console
    
    code .
     2\. VS Code 

extensions installation: C/C++, CMake Tools (e.g. Install in WSL:Ubuntu-24.04)

Some screenshots:

*Geant4 Version:*Geant4-11.3.2
Operating System:Win11+WSL2+Ubuntu20.04/22.04/24.04LTS
*Compiler/Version:*system compiler-GCC 11.4 for Ubuntu20.04/22.04 and GCC 13.3 for Ubuntu24.04
CMake Version:3.24.0 for Ubuntu20.04 / 3.22.1 for Ubuntu22.04 / 3.28.3 for Ubuntu24.04


1 Like