Fedora 环境搭建记录

12 min
WARNING

这是在 Fedora 42 KDE Plasma Desktop 上的配置记录,所有指令请参考官网最新版本。

更新系统包

sudo dnf update

dnf 换源

根据 https://mirrors.tuna.tsinghua.edu.cn/help/fedora/.

# backup
sudo mv /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.bak
sudo mv /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.bak
# modify
sed -e 's|^metalink=|#metalink=|g' \
    -e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \
    -i.bak \
    /etc/yum.repos.d/fedora.repo \
    /etc/yum.repos.d/fedora-updates.repo

字体

我比较喜欢 MesloLGS nerd font 字体,前往 https://www.nerdfonts.com/font-downloads 下载得到 Meslo.zip 压缩包,解压后得到 Meslo 文件夹。

然后将 Meslo 文件夹移动到 ~/.local/share/fonts/ 或者 /usr/share/fonts/ 目录下:

sudo mv -r Meslo /usr/share/fonts

然后更新字体缓存:

sudo fc-cache -fv

接着验证是否安装成功:

fc-list | grep "Meslo"

AppImage

使用 appimagelauncher 管理 AppImage 文件。

sudo dnf install appimagelauncher

Flatpak

根据 https://flatpak.org/setup/fedora 的提示进行配置。

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

然后下载 flatseal 管理权限(fedora 自带了 flatpak 应用权限管理,所以也可以不用装)

sudo dnf install flatseal

同步系统时间

timedatectl set-local-rtc 1 --adjust-system-clock

安装常用软件

(neo)vim

sudo dnf install vim
sudo dnf install neovim

当然顺便也要卸载 nano 啦:

sudo dnf remove nano

clash-verge

前往 https://clashverge.net/downloads/ 下载最新版本的 rpm 包。

sudo dnf install ./Clash.Verge_2.3.0_amd64.rpm

然后前往配置文件设置代理。我主要使用 https://38nthu.xyz/(可能现在无法访问)。以及 https://mojie.app、https://ikuuu.org/ 作为应急情况。之后前往系统设置,添加自启动项。

zsh

# install
sudo dnf install zsh

# set zsh as the default shell
chsh -s $(which zsh)

# verify after re-login
echo $SHELL

# install oh-my-zsh
sudo dnf install curl git
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# 安装 zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

然后设置 oh-my-zsh. 启用一些插件

plugins=(git zsh-autosuggestions z command-not-found colored-man-pages colorize conda-env copyfile copypath fzf python uv)

一些常用的快捷键(用 bindkey 查看,我不太确定上面的插件有没有进行设置,记得确认一下):

快捷键功能
Ctrl + A移动到行首
Ctrl + E移动到行尾
Ctrl + U删除光标前的内容
Ctrl + K删除光标后的内容
Ctrl + W删除光标前一个单词
Ctrl + T使用 fzf 搜索文件
Alt + C使用 fzf 查找文件夹并进入

fcitx5

sudo dnf install fcitx5
sudo dnf remove ibus

查看当前会话使用的是 wayland 还是 xorg:

echo $XDG_SESSION_TYPE

对我而言是 wayland。 然后根据 https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland 中的说明,将以下内容写入 ~/.profile~/.zshrc

export XMODIFIERS=@im=fcitx

然后修改文件 ~/.config/imsettings/xinputrc (实际上是 /etc/X11/xinit/xinput.d/xcompose.conf 的软链接),删除

GTK_IM_MODULE=xim
QT_IM_MODULE=xim

这两行(需要的话记得备份)

然后添加到自启动应用程序中。重启以查看是否生效。然后配置中文输入法

sudo dnf install fcitx5-rime
sudo dnf install fcitx5-chinese-addons

然后根据 https://github.com/iDvel/rime-ice 安装 rime-ice:

cd ~/.local/share/fcitx5/
mv rime rime.bak # backup, not neccesary
git clone https://github.com/iDvel/rime-ice --depth=1 rime

Git

git config --global set user.name xxx
git config --global set user.email xxx

当然我是保存了 ~/.gitconfig 文件,直接复制到家目录就行了

ssh

根据 https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent 设置连接 github 的 ssh key。

ssh-keygen -t ed25519 -C "2823324228@qq.com" # 保存至/home/kinnariya/.ssh/id_ed25519_github文件中
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_github

然后去 https://github.com/settings/keys 添加公钥

cat ~/.ssh/id_ed25519_github.pub

测试连接

ssh -T git@github.com

自动启动 ssh-agent:向 ~/.zshrc 中加入

# ssh agent
# 启动 ssh-agent 并添加 ssh 密钥
if ! pgrep -u $USER ssh-agent > /dev/null; then
    eval "$(ssh-agent -s)"
fi
ssh-add -l &>/dev/null || ssh-add ~/.ssh/id_ed25519_github &>/dev/null

TLP

sudo dnf install tlp
flatpak install tlpui # 图形界面,方便设置

Google Chrome & edge

Chrome 前往官网下载。登录后自动同步历史、插件等。

然后 Edge(根据 https://discussion.fedoraproject.org/t/install-edge/67186/4):

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo dnf config-manager addrepo --from-repofile='https://packages.microsoft.com/yumrepos/edge/config.repo'
sudo dnf update --refresh
sudo dnf install microsoft-edge-stable

然后卸载 Firefox:

sudo dnf remove firefox

Folo

前往 https://github.com/RSSNext/Folo/releases 安装。

QQ、微信

可以选择 flatpak,也可以就用官网的(如果不care扫盘的风险的话)

微信在 wayland 下无法输入中文,可以通过修改环境变量来修补:将 /usr/share/applications/wechat.desktop 中的

Exec=/usr/bin/wechat %U

修改为

Exec=env QT_IM_MODULE=fcitx /usr/bin/wechat %U

即可

Telegram

sudo dnf install telegram

vscode & cursor

vscode 前往官网下载 rpm 包:https://code.visualstudio.com/

cursor 前往官网下载 appimage 格式:https://www.cursor.com/

obsidian

flatpak install obsidian

onedrive

使用 onedriver https://github.com/jstaf/onedriver

sudo dnf copr enable jstaf/onedriver
sudo dnf install onedriver

yazi

根据 Installation | Yazi

sudo dnf copr enable lihaohong/yazi
sudo dnf install yazi

然后向 .zshrc 中加入

function yy() {
  local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
  yazi "$@" --cwd-file="$tmp"
  if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
    builtin cd -- "$cwd"
  fi
  rm -f -- "$tmp"
}

飞书

前往官网下载 下载飞书 App 及桌面客户端 - 飞书官网。也可以直接使用网页版。

Google docs

先卸载 libreoffice:

sudo dnf remove libreoffice*

然后去 https://docs.google.com/ 进行文档编写。

WPS

去官网 https://linux.wps.cn/ 下载。

腾讯会议

flatpak install wemeet

Minecraft

根据官网信息(https://prismlauncher.org/download/)安装 Prism Launcher。

sudo dnf copr enable g3tchoo/prismlauncher
sudo dnf install prismlauncher

或者直接使用 flatpak 安装:

flatpak install PrismLauncher

Docker

根据 https://docs.docker.com/engine/install/fedora/:

sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

sudo dnf -y install dnf-plugins-core
sudo dnf-3 config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

因为我不希望 docker 自启动,所以设置 alias:

alias docker_start="sudo systemctl start docker"
alias docker_stop="sudo systemctl stop docker && sudo systemctl stop docker.socket"

否则可以使用

sudo systemctl enable --now docker

每次使用 docker 都需要 root 权限,很麻烦,可以按照官方设置(https://docs.docker.com/engine/install/linux-postinstall/):

sudo groupadd docker
sudo usermod -aG docker $USER

然后重启,重启后运行

newgrp docker

之后就可以用非 root 权限运行 docker 命令了。

然后配置 nvidia-docker-toolkit,因为 fedora 的 g++ 版本较新,nvidia 官方并没有支持,所以有时候就需要 docker 配置一下环境(也有其他方案,可以参考 CUDA 一节)。首先安装 NVIDIA Container Toolkit

curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \
sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo

export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.17.8-1
sudo dnf install -y \
    nvidia-container-toolkit-${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
    nvidia-container-toolkit-base-${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
    libnvidia-container-tools-${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
    libnvidia-container1-${NVIDIA_CONTAINER_TOOLKIT_VERSION}

然后重启 docker:

sudo systemctl restart docker

之后就可以拉取 nvidia 官方镜像了。Jkk

fzf

配置几个好用的函数(alias):

alias fzf_process="ps aux | fzf --layout=reverse --border --height=80%"
open() {
  local target
  target=$(fzf \
    --preview '[[ -d {} ]] && tree -C {} | head -100 || bat --style=numbers --color=always --line-range=:100 {} 2>/dev/null || cat {} 2>/dev/null' \
    --preview-window=right:60%:wrap \
    --height=80% \
    --layout=reverse \
    --border \
    --bind "ctrl-o:execute(nvim {})+abort")

  if [[ -n "$target" ]]; then
    nvim "$target"
  fi
}

YesPlayMusic

flatpak install io.github.qier222.YesPlayMusic

其他

sudo dnf install fastfetch tldr
sudo dnf install git-lfs
sudo dnf install strace thefuck # 蒋炎岩 os 课上用了

# lazygit, https://copr.fedorainfracloud.org/coprs/atim/lazygit/
sudo dnf copr enable atim/lazygit
sudo dnf install lazygit

# uv, https://github.com/astral-sh/uv
curl -LsSf https://astral.sh/uv/install.sh | sh

系统快捷键设置

前往 Settings > Keyboard > Shortcuts 进行设置。

美化

我没做美化,因为觉得原皮挺好看的

也是经典壁纸了哈哈
也是经典壁纸了哈哈

访问 Windows 文件

有时候想直接访问 Windows 中的文件,但是每次开机后第一次访问都要输密码(udisk 导致的),稍显麻烦,根据 https://dynacont.net/documentation/linux/udisks2_polkit_Allow_unauthenticated_mounting/ 可以创建 /etc/polkit-1/rules.d/10-udisks2.rules 文件并写入:

// See the polkit(8) man page for more information
// about configuring polkit.

// Allow udisks2 to mount devices without authentication
// for users in the "wheel" group.
polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.udisks2.filesystem-mount-system" ||
         action.id == "org.freedesktop.udisks2.filesystem-mount") &&
        subject.isInGroup("wheel")) {
        return polkit.Result.YES;
    }
});

然后前往系统设置 > Disks & Cameras > Device Auto-Mount,勾选需要自动挂载的分区即可,重启后生效。

多屏设置

需要使用独显,才能获得较为流畅的多屏体验。安装驱动的方法见下面

环境配置

Python

根据官网信息 Installing Miniconda - Anaconda 安装 miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash ~/Miniconda3-latest-Linux-x86_64.sh

然后设置 pip 源:

# 设置为清华源
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
# 设置代理,注意代理地址可能不一样 :doge:
pip config set global.proxy https://127.0.1:7890

设置 conda 源:

channels:
  - defaults
  - conda-forge
  - nodefaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
channel_priority: flexible

然后安装 wandb(其他工具包同理,都可以用 uv 来装):

uv tool install wandb
# 登录
wandb login

rust

参考 https://developer.fedoraproject.org/tech/languages/rust/rust-installation.html

sudo dnf install cargo rust

或者使用 rust 官方的安装指导:

sudo dnf install rustup
rustup-init
# 根据提示进行安装后
. "$HOME/.cargo/env"

这两者不能同时使用,官方推荐使用后者。

C/C++/CUDA

安装 xmake:

sudo dnf install xmake

安装 CUDA(安装前记得备份系统):

sudo dnf install xorg-x11-drv-nvidia-cuda

然后重启电脑,进入终端,输入 nvidia-smi 检验是否安装成功。

前往 vscode,安装 clangd 插件。然后安装 clangd lsp:

sudo dnf install clang-tools-extra

因为 nvidia 官方现在没有支持 Fedora 42 的 cudatoolkit 安装,所以我选择使用 conda 来安装(https://anaconda.org/nvidia/cuda-toolkit,也可以直接安装 Fedora 41 的,见下):

conda create -n cuda python=3.10.16
conda activate cuda
conda install nvidia/label/cuda-11.8.0::cuda-toolkit

运行

nvcc -V

得到输出

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

编译以下 hello.cu 文件:

#include <stdio.h>

__global__ void cuda_say_hello() {
  printf("Hello world, CUDA! %d\n", threadIdx.x);
}

int main() {
  printf("Hello world, CPU\n");
  cuda_say_hello<<<1, 1>>>();

  cudaError_t cudaerr = cudaDeviceSynchronize();
  if (cudaerr != cudaSuccess)
    printf("kernel launch failed with error \"%s\".\n",
           cudaGetErrorString(cudaerr));
  return 0;
}

编译并运行:

nvcc hello.cu -o hello
./hello

得到输出:

Hello world, CPU
Hello world, CUDA! 0

此时相关文件在 $CONDA_PATH/targets/x86_64-linux/ 文件夹下,可以配置 .clangd 文件为:

CompileFlags:
  Add: [
    "-L/home/kinnariya/miniconda3/envs/cuda/targets/x86_64-linux/lib",
    "-I/home/kinnariya/miniconda3/envs/cuda/targets/x86_64-linux/include"
  ]

这里我的 $CONDA_PATH 即为 /home/kinnariya/miniconda3/envs/cuda/targets/x86_64-linux/。重启 vscode,此时可以正常使用 clangd 来编写 cuda 文件了。

之后安装 g++,以支持 C++ 编译:

sudo dnf install gcc-c++

也可以直接安装 cuda-toolkit(根据 https://developer.nvidia.com/cuda-downloads):

sudo dnf config-manager addrepo --from-repofile https://developer.download.nvidia.com/compute/cuda/repos/fedora41/x86_64/cuda-fedora41.repo
sudo dnf clean all
sudo dnf config-manager setopt cuda-fedora41-$(uname -m).exclude=nvidia-driver,nvidia-modprobe,nvidia-persistenced,nvidia-settings,nvidia-libXNVCtrl,nvidia-xconfig
sudo dnf -y install cuda-toolkit-12-9 # 注意 cuda-toolkit 的版本,这里我用的是 12.9,建议参考官方说明

由于 fedora 42 的 g++ 版本为 15,太新了,需要手动安装 g++14(参考 https://forum.level1techs.com/t/cuda-12-9-on-fedora-42-guide-including-getting-cuda-samples-running/230769

sudo dnf install gcc14.x86_64 gcc14-c++.x86_64 cuda-nvcc-12-9

然后更新环境变量:

export CUDAHOSTCXX=/usr/bin/g++-14
export CPATH=/usr/include/openmpi-x86_64:$CPATH
export PATH=$PATH:/usr/lib64/openmpi/bin
export CC=/usr/bin/gcc-14
export CXX=/usr/bin/g++-14
export NVCC_CCBIN=/usr/bin/g++-14

最后将所有库函数和 includes 路径添加到环境变量中

export LD_LIBRARY_PATH=/usr/local/cuda-12.9/targets/x86_64-linux/lib:$LD_LIBRARY_PATH
export CPATH=/usr/local/cuda-12.9/targets/x86_64-linux/include:$CPATH
export PATH=/usr/local/cuda-12.9/bin:$PATH

还需要修改一些源代码:修改 /usr/local/cuda-12.9/targets/x86_64-linux/include/crt/math_functions.h

  *
  * \note_accuracy_double
  */
-extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double                 sinpi(double x);
+extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double                 sinpi(double x) noexcept (true);
 /**
  * \ingroup CUDA_MATH_SINGLE
  * \brief Calculate the sine of the input argument
@@ -2576,7 +2576,7 @@
  *
  * \note_accuracy_single
  */
-extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float                  sinpif(float x);
+extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float                  sinpif(float x) noexcept (true);
 /**
  * \ingroup CUDA_MATH_DOUBLE
  * \brief Calculate the cosine of the input argument
@@ -2598,7 +2598,7 @@
  *
  * \note_accuracy_double
  */
-extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double                 cospi(double x);
+extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ double                 cospi(double x) noexcept (true);
 /**
  * \ingroup CUDA_MATH_SINGLE
  * \brief Calculate the cosine of the input argument
@@ -2620,7 +2620,7 @@
  *
  * \note_accuracy_single
  */
-extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float                  cospif(float x);
+extern __DEVICE_FUNCTIONS_DECL__ __device_builtin__ float                  cospif(float x) noexcept (true);
 /**
  * \ingroup CUDA_MATH_DOUBLE
  * \brief  Calculate the sine and cosine of the first input argument

.clangd 文件的设置同上,将所有 /home/kinnariya/miniconda3/envs/cuda/targets/x86_64-linux/ 修改为 /usr/local/cuda-12.9 即可。

博客

sudo dnf install node npm pnpm yarn

LaTex

我采用 medium 安装,包含了常用的宏包。

# sudo dnf install texlive-scheme-basic
sudo dnf install texlive-scheme-medium
# sudo dnf install texlive-scheme-full

发现中文有报错

File `ctex.sty' not found.LaTeX

于是安装 ctex 宏包:

sudo dnf install texlive-ctex

其他使用中发现缺失的宏包同理。

清理软件包

为了方便,直接去软件商店手动卸载不需要的软件包。

sudo dnf clean all
sudo dnf autoremove