系统环境 IT小强xqitw.cn 2021年12月26日 19:59 摘要: wsl2下开发环境搭建,xfce4桌面环境配置,常用开发工具安装,以及一些可能遇到的问题的解决方案。 [TOCM] > Ubuntu 20.04.2 LTS (GNU/Linux 5.4.72-microsoft-standard-WSL2 x86_64) ### WSL 2 全局设置 你可以通过将 .wslconfig 文件放置在用户文件夹的根目录下(即 C:\Users\<YourUserName>\.wslconfig)来配置全局 WSL 选项。此文件中许多配置与 WSL 2 有关,你需要运行 wsl --shutdown 来关闭 WSL 2 虚拟机,重启 WSL 2 ,以确保这些配置生效。 ``` [wsl2] # GUI guiApplications=true # 自定义 Linux 内核的绝对路径 kernel=<path> # 给 WSL 2 虚拟机分配的内存大小 memory=<size> # 为 WSL 2 虚拟机分配的处理器核心数量 processors=<number> # 为 WSL 2 虚拟机分配的交换空间,0 表示没有交换空间 swap=<size> # 自定义交换虚拟磁盘 vhd 的绝对路径 swapFile=<path> # 是否允许将 WSL 2 的端口转发到主机(默认为 true) localhostForwarding=<bool> # `<path>` 必须是带反斜杠的绝对路径,例如 `C:\\Users\\kernel` # `<size>` 必须在后面加上单位,例如 8 GB 或 512 MB [experimental] autoMemoryReclaim=gradual networkingMode=mirrored dnsTunneling=true firewall=true autoProxy=true ``` ### 设置默认用户为 root ``` # cmd 执行以下命令 Ubuntu config --default-user root ``` ### 切换阿里镜像源 参考:[https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.6af01b11ahWtVr](https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.6af01b11ahWtVr "https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.6af01b11ahWtVr") ```shell # 先备份 sudo cp /etc/apt/sources.list /etc/apt/sources_init.list 编辑 /etc/apt/sources.list 文件 写入以下内容 # ----------- 阿里源 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse # ----------- 阿里源 # 更新 sudo apt-get update sudo apt-get -f install sudo apt-get upgrade ``` ### 安装python3-pip ```shell sudo apt-get install python3-pip ``` ### 安装 pipx ```shell python3 -m pip install --user pipx python3 -m userpath append ~/.local/bin ``` ### 安装宝塔面板 ```shell if [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh ed8484bec ``` ### xfce4桌面 #### 安装xfce4桌面 ```shell # 安装 sudo apt-get install xfce4 xfce4-terminal # 移除屏保等无用项 sudo apt-get purge xscreensaver gnome-screensaver sudo apt-get purge xscreensaver gnome-screensaver light-locker i3lock ``` #### 启动 xfc4桌面 > windows10 上先安装并启动x-server软件 如:x410 ```shell # 在 /etc/profile.d 目录下 新建文件 cof-xfce4.sh 写入以下配置 export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0 # 完整启动 startxfce4 # 仅启动核心 xfsettingsd --sm-client-disable; xfce4-panel --sm-client-disable --disable-wm-check & ``` #### xfce4桌面美化 https://www.xfce-look.org/ 搜索想要的主题和图标 主题放置路径: /usr/share/themes 图标放置路径: /usr/share/icons ### 安装拼音输入法 ```shell # 先卸载 ibus sudo apt-get remove ibus sudo apt-get autoremove # 安装中文字体和输入法 sudo apt-get install fonts-noto fcitx fcitx-pinyin # 在 /etc/profile.d 目录下 新建文件 cof-fcitx.sh 写入以下配置 export INPUT_METHOD=fcitx export XMODIFIERS=@im=fcitx export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx ``` ### 浏览器安装 #### 安装火狐浏览器 ```shell sudo apt-get install firefox ``` #### 安装谷歌浏览器 ```shell # 下载 wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb # 安装 sudo dpkg -i google-chrome-stable_current_amd64.deb ``` #### 谷歌浏览器允许 root 用户运行 ```shell vim /opt/google/chrome/google-chrome # 找到最后一行修改为: exec -a "$0" "$HERE/chrome" "$@" --no-sandbox # 然后:w保存,就能正常启动google浏览器了 ``` ### 安装配置pyenv ```shell # 安装 curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash # 配置 export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" ``` ### 终端安装配置 #### 安装tilix ```shell sudo apt-get install tilix ``` #### 安装zsh ```shell # 安装 sudo apt-get install -y zsh # 设置默认 chsh -s /bin/zsh ``` #### 安装及配置Oh My Zsh ```shell # 自动下载并安装 sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ``` ### 修改主题 ```shell # 编辑 ~/.zshrc ZSH_THEME="obraun" ``` #### 自定义Oh My Zsh主题 ```shell # Clean, simple, compatible and meaningful. # Tested on Linux, Unix and Windows under ANSI colors. # It is recommended to use with a dark background. # Colors: black, red, green, yellow, *blue, magenta, cyan, and white. # # Mar 2013 Yad Smood # VCS YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} " YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}" YS_VCS_PROMPT_SUFFIX="%{$reset_color%}" YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x" YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o" # Git info local git_info='$(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}" ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX" ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY" ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN" # HG info local hg_info='$(ys_hg_prompt_info)' ys_hg_prompt_info() { # make sure this is a hg dir if [ -d '.hg' ]; then echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}" echo -n $(hg branch 2>/dev/null) if [ -n "$(hg status 2>/dev/null)" ]; then echo -n "$YS_VCS_PROMPT_DIRTY" else echo -n "$YS_VCS_PROMPT_CLEAN" fi echo -n "$YS_VCS_PROMPT_SUFFIX" fi } local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})" # Prompt format: # # PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE # $ COMMAND # # For example: # # % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0 # $ PROMPT="%(#,%{$fg[yellow]%}%n%{$reset_color%},%{$fg[cyan]%}%n)%{$fg[white]%}@%{$fg[green]%}%m%{$fg[white]%}:%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ ${hg_info}\ ${git_info}\ \ %{$fg[white]%}[%*] $exit_code %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" ``` ### 安装配置ssh #### 生成公钥私钥 ```shell ssh-keygen -t rsa ssh-keygen -m PEM -t rsa -b 4096 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh ``` #### 重新生成主机密钥文件 ```shell ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key ``` #### ssh一些配置 ```shell #允许 root用户登录 PermitRootLogin yes # 允许密码登录 PasswordAuthentication yes ``` ### 部分错误的解决方案 #### 安装mysqlclient报错 ```shell sudo apt-get install libmysqlclient-dev ```