建议使用debian系(包含ubuntu)系统进行开发,其他系统需要替换apt安装命令
纯新手可能需要摸索使用,请自行利用搜索引擎
注意事项:
- 建议使用debian系(包含ubuntu)系统进行开发,其他系统需要替换apt安装命令
- 系统需要专业版,并在 控制面板->程序与功能->启用或关闭windows功能中开启
[Hyper-V,适用于linux的windows子系统,虚拟机平台]
创建wsl
应用商店搜索debian并安装,或者网上找debian的wsl镜像
迁移镜像到或备份恢复镜像
# 查询已安装的镜像
wsl -l
# 导出镜像 wsl --export 名称 导出位置,可为绝对路径
wsl --export Debian debian.tgz
# 导入镜像 wsl --import 名称 放在哪个位置 之前导出的文件
wsl --import debian D:\wsl\debian debian.tgz
防火墙配置
# 允许防火墙(wsl访问windows),在powershell执行
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
命令行输入wsl即可进入linux系统,推荐使用root进行操作
加速下载速度
debian换源
这里演示清华源,debian12(bookworm)的安装方式: https://mirrors.tuna.tsinghua.edu.cn/help/debian/
# 备份
mv /etc/apt/sources.list /etc/apt/sources.list.bak
# 恢复 cp /etc/apt/sources.list.bak /etc/apt/sources.list
# 覆盖配置 (echo到> /etc/apt/sources.list需要一起复制)
echo "# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" \
> /etc/apt/sources.list
# 应用配置更新
apt update -y
# 更新软件(非必须)
apt upgrade -y
代理设置(非必须,无代理不设置)
# 安装vim
apt install -y vim
# 添加自动设置代理和代理命令
vim ~/.bashrc # 如果使用zsh则为vim ~/.zshrc
# 按i进入编辑模式,在空行粘贴以下内容,按esc退出编辑模式,输入wq保存
# ---写入内容
function set_proxy() {
proxy_server=$(grep -m 1 '^nameserver ' /etc/resolv.conf | sed 's/^nameserver //')
proxy_port=7890
export http_proxy=http://$proxy_server:$proxy_port
export HTTP_PROXY=$http_proxy
export https_proxy=$http_proxy
export HTTPS_PROXY=$http_proxy
export ftp_proxy=$http_proxy
export FTP_PROXY=$http_proxy
export all_proxy=$http_proxy
export ALL_PROXY=$http_proxy
git config --global http.proxy $proxy_server:$proxy_port
git config --global https.proxy $proxy_server:$proxy_port
}
function unset_proxy() {
unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY ftp_proxy FTP_PROXY all_proxy ALL_PROXY
git config --global --unset http.proxy
git config --global --unset https.proxy
}
set_proxy
# ---结束写入内容
source ~/.bashrc
# 开启和关闭代理则为set_proxy,unset_proxy
# 如果需要自定义代理则修改proxy_server和proxy_port,默认为自动寻找windows的ip
软件安装
# 基础环境
apt-get install build-essential cmake gdb git curl wget net-tools -y
# python环境(自选)
# miniconda https://docs.anaconda.com/free/miniconda/index.html
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod 777 Miniconda3-latest-Linux-x86_64.sh
# 用户协议可以按q快速阅读,会询问是否初始化命令行,如果没有初始化进入安装目录,bin找到conda,输入./conda init --all
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
操作完成后可在clion里面使用wsl进行构建,如果缺失其他环境请自行安装
wsl美化
# sh美化
apt install zsh -y
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# 修改.zshrc的以下key
vim ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(
z
git
zsh-syntax-highlighting
zsh-autosuggestions
)
# 进入bash初始化zsh的conda,或者进入conda安装目录初始化也行
bash
conda init zsh
# 重回zsh
zsh
source ~/.zshrc
# vim美化
git clone https://github.com/chxuan/vimplus.git ~/.vimplus
cd ~/.vimplus
./install.sh