11 minutes
使用wsl安装archlinux,Geant4及ROOT
官网:
https://learn.microsoft.com/zh-cn/windows/wsl/install
使用wsl安装linux
1. 安装wsl
打开终端管理员,win11鼠标右键点击win菜单可以找到。
# PowerShell
wsl --install
遇到如下报错:
# PowerShell
PS C:\Users\gouz> wsl --install
正在下载: Ubuntu
正在安装: Ubuntu
由于未安装所需的特性,无法启动操作。
错误代码: Wsl/InstallDistro/Service/RegisterDistro/CreateVm/HCS/HCS_E_SERVICE_NOT_AVAILABLE
按照旧版本的步骤先启用适用于linux的windows子系统,然后启用虚拟机功能,然后关机重启。
# PowerShell
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
重启之后再次打开终端管理员,输入:
# PowerShell
wsl --install
默认安装的是Ubuntu,在windows终端内输入
# PowerShell
wsl -l -o
可以查看在线商店可用的linux分发版的列表。 我更换成了archlinux,
# PowerShell
wsl --install -d archlinux
2. 为archlinux创建非root用户
先在windows终端中打开wsl archlinux
# PowerShell
wsl -d archlinux
进入archlinux默认是root用户,先安装sudo软件包
# bash
pacman -Syu
pacman -S sudo
然后创建非root用户,注意下面的命令仍然是在archlinux的终端中输入。
# bash
useradd -m -G wheel -s /bin/bash username
passwd username #为用户username设置密码
然后还需要将用户配置为sudo用户
# bash
pacman -S nano #nano是文本编辑器,我个人比较喜欢用,感觉适合小白
nano /etc/sudoers
打开文件后ctrl+F搜索wheel,然后将%wheel ALL=(ALL:ALL) ALL 这一行的注释删掉,也就是删掉“# %wheel ALL=(ALL:ALL) ALL”前面的“#”,随后ctrl+X退出,输入Y按下回车保存。 然后切换成新建的用户测试一下sudo是否能够使用。
# bash
su username
sudo pacman -Syu
如果需要,可以将wsl的archlinux默认启动用户改成刚刚新建的用户。打开windows终端
#PowerShell
wsl --manage archlinux --set-default-user username
“wsl –help"可以查看更多关于wsl的命令选项。
3. wsl配置文件 (参考)
[wsl2]
memory=8GB
processors=8
[experimental]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
sparseVhd=true
文件存放于c盘/用户/用户名目录下,文件名为”.wslconfig"。这个我也是搬的别的大佬的。
安装ROOT
1. 包管理器安装(推荐)
打开终端,输入,
#bash
sudo pacman -S root
安装完之后打开root检查一下,
# bash
root
2. 从源码构建(不推荐)
不推荐,不推荐,不推荐!我自己已经放弃了,根本不知道要安装多少依赖 https://root.cern.ch/install/ 打开链接翻到最下面的“Build from source”处,跟着输入命令即可
当然得先安装一下git依赖和camke等依赖。这里的依赖没安装完全,根据报错自行添加吧。
# bash
sudo pacman -S git
sudo pacman -S base-devel gcc cmake libx11 libxpm libxft libxext
sudo pacman -S gsl giflib libjpeg-turbo libtiff libpng fontconfig
sudo pacman -S python
sudo pacman -S xrootd davix
安装完git之后复制粘贴官网教程中的命令即可,可能需要科学上网。
# bash
mkdir root && cd root
git clone --branch latest-stable --depth=1 https://github.com/root-project/root.git root_src
mkdir root_build root_install && cd root_build
cmake -DCMAKE_INSTALL_PREFIX=../root_install ../root_src
一直报错,我放弃了。
报错
我在cmake时出现报错,此时依赖我只安装了cmake和git:
# bash
[nine@DESKTOP-VL1ESD8 root_build]$ cmake -DCMAKE_INSTALL_PREFIX=../root_install ../root_src/
CMake Deprecation Warning at CMakeLists.txt:32 (cmake_policy):
The OLD behavior for policy CMP0116 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:32 (cmake_policy):
The OLD behavior for policy CMP0135 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
问过ai之后发现是缺少依赖,还得安装base-devel, gcc。
重新cmake又遇到报错:
-- Looking for X11
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:227 (message):
Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB Xpm Xft Xext)
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:591 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/Modules/FindX11.cmake:684 (find_package_handle_standard_args)
cmake/modules/SearchInstalledSoftware.cmake:80 (_find_package)
cmake/modules/SearchInstalledSoftware.cmake:423 (find_package)
CMakeLists.txt:287 (include)
复制给ai,发现还得安装libx11 libxpm libxft libxext。安装完之后cmake继续报错
# bash
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:227 (message):
Could NOT find Python3 (missing: Python3_EXECUTABLE Interpreter) (Required
is at least version "3.0")
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:591 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake/Modules/FindPython/Support.cmake:4082 (find_package_handle_standard_args)
/usr/share/cmake/Modules/FindPython3.cmake:640 (include)
cmake/modules/SearchInstalledSoftware.cmake:80 (_find_package)
interpreter/llvm-project/llvm/CMakeLists.txt:892 (find_package)
这是因为缺少python3解释器。 还注意到在cmake过程中的输出信息:
# bash
-- Could NOT find GIF (missing: GIF_LIBRARY GIF_INCLUDE_DIR)
-- Found PNG: /usr/lib/libpng.so (found version "1.6.50")
-- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
-- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
-- Could NOT find GSL: (Required is at least version "1.10") (found GSL_INCLUDE_DIR-NOTFOUND)
-- GSL not found. Set variable GSL_ROOT_DIR to point to your GSL installation
-- Alternatively, you can also enable the option 'builtin_gsl' to build the GSL libraries internally'
-- For the time being switching OFF 'mathmore' option
这是要安装gsl giflib libjpeg-turbo libtiff libpng freetype fontconfig,freetype安装不了,跳过,然后cmake继续报错:
# bash
[nine@DESKTOP-VL1ESD8 root_build]$ cmake -DCMAKE_INSTALL_PREFIX=../root_install ../root_src/
CMake Deprecation Warning at CMakeLists.txt:32 (cmake_policy):
The OLD behavior for policy CMP0116 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:32 (cmake_policy):
The OLD behavior for policy CMP0135 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- The C compiler identification is GNU 15.1.1
-- The CXX compiler identification is GNU 15.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/sbin/git (found version "2.50.0")
-- Building ROOT version 6.36.000
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - NOTFOUND
-- Found GCC. Major version 15, minor version 1
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test GLIBCXX_USE_CXX11_ABI
-- Performing Test GLIBCXX_USE_CXX11_ABI - Success
-- ROOT default compression algorithm: zlib
-- Checking internet connectivity
-- Checking internet connectivity - found
-- Looking for ZLib
-- Found ZLIB: /usr/lib/libz.so (found version "1.3.1")
-- Looking for nlohmann/json.hpp
-- nlohmann/json.hpp not found. Switching on builtin_nlohmannjson option
-- Looking for Freetype
-- Found Freetype: /usr/lib/libfreetype.so (found version "2.13.3")
-- Looking for PCRE
-- Found PCRE2: /usr/include (found version "10.45")
-- Looking for LZMA
-- Looking for lzma_auto_decoder in /usr/lib/liblzma.so
-- Looking for lzma_auto_decoder in /usr/lib/liblzma.so - found
-- Looking for lzma_easy_encoder in /usr/lib/liblzma.so
-- Looking for lzma_easy_encoder in /usr/lib/liblzma.so - found
-- Looking for lzma_lzma_preset in /usr/lib/liblzma.so
-- Looking for lzma_lzma_preset in /usr/lib/liblzma.so - found
-- Found LibLZMA: /usr/lib/liblzma.so (found version "5.8.1")
-- Looking for xxHash
-- Found xxHash: /usr/lib/libxxhash.so (found suitable version "0.8.3", minimum required is "0.8")
-- Looking for ZSTD
-- Found ZSTD: /usr/lib/libzstd.so
-- Looking for LZ4
-- Found LZ4: /usr/lib/liblz4.so (found version "1.10.0")
-- Looking for X11
-- Found X11: /usr/include found components: Xpm Xft Xext
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so;/usr/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- X11_INCLUDE_DIR: /usr/include
-- X11_LIBRARIES: /usr/lib/libSM.so;/usr/lib/libICE.so;/usr/lib/libX11.so;/usr/lib/libXext.so
-- X11_Xpm_INCLUDE_PATH: /usr/include
-- X11_Xpm_LIB: /usr/lib/libXpm.so
-- X11_Xft_INCLUDE_PATH: /usr/include
-- X11_Xft_LIB: /usr/lib/libXft.so
-- X11_Xext_INCLUDE_PATH: /usr/include
-- X11_Xext_LIB: /usr/lib/libXext.so
-- Found GIF: /usr/lib/libgif.so (found version "5.2.2")
-- Found PNG: /usr/lib/libpng.so (found version "1.6.50")
-- Found JPEG: /usr/lib/libjpeg.so (found version "80")
-- Found TIFF: /usr/lib/libtiff.so (found version "4.7.0")
-- Looking for GSL
-- Found GSL: /usr/include (found suitable version "2.8", minimum required is "1.10")
-- Looking for Python
-- Could NOT find Python3 (missing: Python3_NumPy_INCLUDE_DIRS NumPy) (found suitable version "3.13.5", minimum required is "3.8")
-- Looking for OpenGL
-- Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY OPENGL_INCLUDE_DIR)
-- OpenGL (with GLU) not found. Switching off opengl option
-- Looking for LibXml2
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.14.4")
-- Found OpenSSL: /usr/lib/libcrypto.so (found version "3.5.1") found components: SSL
-- Looking for SQLite
-- Found PkgConfig: /usr/sbin/pkg-config (found version "2.5.1")
-- Found Sqlite: /usr/include
-- Looking for CFITSIO
-- Could NOT find CFITSIO (missing: CFITSIO_LIBRARY CFITSIO_INCLUDE_DIR)
-- CFITSIO not found. You can enable the option 'builtin_cfitsio' to build the library internally'
-- For the time being switching off 'fitsio' option
-- Looking for XROOTD
CMake Warning at cmake/modules/SearchInstalledSoftware.cmake:80 (_find_package):
By not providing "FindXRootD.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "XRootD", but
CMake did not find one.
Could not find a package configuration file provided by "XRootD" with any
of the following names:
XRootDConfig.cmake
xrootd-config.cmake
Add the installation prefix of "XRootD" to CMAKE_PREFIX_PATH or set
"XRootD_DIR" to a directory containing one of the above files. If "XRootD"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
cmake/modules/SearchInstalledSoftware.cmake:997 (find_package)
CMakeLists.txt:287 (include)
-- XROOTD not found, enabling 'builtin_xrootd' option
-- Found OpenSSL: /usr/lib/libcrypto.so (found version "3.5.1")
-- Downloading and building XROOTD version 5.8.0
-- Checking for module 'davix>=0.6.4'
-- Package 'davix' not found
-- Looking for uuid_generate_random in uuid
-- Looking for uuid_generate_random in uuid - found
-- Found libuuid: /usr/include
-- Davix not found, switching ON 'builtin_davix' option.
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for TBB
-- Could NOT find TBB (missing: TBB_ROOT_DIR TBB_INCLUDE_DIR TBB_LIBRARY) (Required is at least version "2020")
-- TBB not found, enabling 'builtin_tbb' option
-- Looking for VDT
-- Could NOT find Vdt (missing: VDT_INCLUDE_DIR VDT_LIBRARY) (Required is at least version "0.4")
-- VDT not found. Ensure that the installation of VDT is in the CMAKE_PREFIX_PATH
-- Switching ON 'builtin_vdt' option
-- Looking for BLAS for optional parts of TMVA
-- Using GSL CBLAS for optional parts of TMVA
-- TMVA: Numpy or Python development package not found for python /usr/sbin/python3.13. Switching off tmva-pymva option
-- PyROOT: development package found. Building for version 3.13.5
-- Performing Test ROOT_HAVE_CXX_ATOMICS_WITHOUT_LIB
-- Performing Test ROOT_HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Building LLVM in 'Release' mode.
CMake Deprecation Warning at interpreter/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
The OLD behavior for policy CMP0114 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
interpreter/llvm-project/llvm/CMakeLists.txt:6 (include)
CMake Deprecation Warning at interpreter/llvm-project/cmake/Modules/CMakePolicy.cmake:11 (cmake_policy):
The OLD behavior for policy CMP0116 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
interpreter/llvm-project/llvm/CMakeLists.txt:6 (include)
CMake Deprecation Warning at interpreter/llvm-project/cmake/Modules/CMakePolicy.cmake:6 (cmake_policy):
The OLD behavior for policy CMP0114 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
interpreter/llvm-project/clang/CMakeLists.txt:6 (include)
CMake Deprecation Warning at interpreter/llvm-project/cmake/Modules/CMakePolicy.cmake:11 (cmake_policy):
The OLD behavior for policy CMP0116 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
interpreter/llvm-project/clang/CMakeLists.txt:6 (include)
CMake Warning (dev) at interpreter/llvm-project/clang/CMakeLists.txt:405 (install):
Policy CMP0177 is not set: install() DESTINATION paths are normalized. Run
"cmake --help-policy CMP0177" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
安装 xrootd davix。不折腾这个了,放弃,改用包管理器安装。
安装Geant4
这里也用简单方法了,从源码构建就放在第一篇帖子里面折腾吧。 https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/ “Arch Users Repository on Arch Linux"处跟着走, 先安装一下依赖,由于有一些依赖官方仓库里面没有,因此可以使用aur助手yay安装aur的包。
# bash
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
yay安装完之后,使用yay安装clhep
# bash
yay -S clhep
根据提示按回车即可。 使用pacman安装其他的依赖(也可以用yay安装)
# bash
sudo pacman -S xerces-c qt6-base openmotif soqt boost
sudo pacman -S qt5-base qt5-tools qt5-svg mesa glu
然后跟着官方教程走。
# bash
git clone https://aur.archlinux.org/geant4.git
cd geant4
如果cmake版本过高,后面可能会报错,先修改一下PKGBUILD里面的cmake设置。
# bash
yay -S coin --editmenu #我也不知道这一步干什么的
nano PKGBUILD
把“-DCMAKE_POLICY_VERSION_MINIMUM=3.5”加载cmake那一堆里。或者
# bash
sudo nano /usr/lib/cmake/Coin-4.0.3/coin-config.cmake
把“cmake_minimum_required(VERSION 2.8.12)”注释掉,也就是在这一行前面加上#。
然后继续,
# bash
makepkg --syncdeps
运行完之后得到一个名为geant4--x86_64.pkg.tar 的文件,例如我的是geant4-11.3.1-1-x86_64.pkg.tar,
# bash
sudo pacman -U geant4-11.3.1-1-x86_64.pkg.tar
差了一步,还得下载data文件,在官网下载所有data文件。把文件解压到/usr/sbin/../share/Geant4/目录下,然后在终端中配置环境,
# bash
nano ~/.bashrc
将“source geant4/pkg/geant4/usr/bin/geant4.sh” 添加到最后。
报错
makepkg –syncdeps 一步出现报错:
# bash
[nine@DESKTOP-VL1ESD8 geant4]$ makepkg --syncdeps
==> Making package: geant4 11.3.1-1 (Thu Jul 3 20:40:04 2025)
==> Checking runtime dependencies...
==> Installing missing dependencies...
[sudo] password for nine:
error: target not found: clhep>=2.4.6.0
==> ERROR: 'pacman' failed to install missing dependencies.
==> Missing dependencies:
-> clhep>=2.4.6.0
-> xerces-c>=3
-> qt6-base
-> openmotif
-> soqt
-> boost
==> Checking buildtime dependencies...
==> ERROR: Could not resolve all dependencies.
应该是缺少这些依赖。pacman安装找不到clhep,这才发现我忘换镜像源了。把换镜像源放在第一步。 安装一下yay,再用yay安装这些pacman中没有的依赖。 依赖安装完之后makepkg –syncdeps继续报错,
# bash
CMake Error at /usr/lib/cmake/Coin-4.0.3/coin-config.cmake:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
Call Stack (most recent call first):
cmake/Modules/G4InterfaceOptions.cmake:127 (find_package)
cmake/Modules/G4CMakeMain.cmake:64 (include)
CMakeLists.txt:49 (include)
-- Configuring incomplete, errors occurred!
==> ERROR: A failure occurred in build().
Aborting...
ai说是cmake版本太高。用yay安装Geant4可以先执行
# bash
yay -S coin --editmenu #我也不知道这一步干什么的
nano PKGBUILD
把“-DCMAKE_POLICY_VERSION_MINIMUM=3.5”加载cmake那一堆里。