Linux四大环境搭建,配置WSL + Archlinux + xfce4开发环境

由于本人开发的某项目IDE使用Windows下的VSCode,而调试在Linux环境下并且需要使用Linux下的图形界面。此时使用虚拟机用来编译/调试开销太大,于是打算配置WSL来解决这个问题。

为了方便使用新版本软件等考虑(本着生命在于折腾的原则),将WSL中的Ubuntu替换Archlinux。

739c50d2b3407bae1854c2497232e44e.png

不得不说,pacman管理器与aur用起来真是爽。最终运行情况

1.png

配置步骤1. 安装WSL (Windows Subsystem for Linux)

参考 https://wiki.archlinux.org/index.php/Install_on_WSL_(简体中文)

开启Windows开发者模式

03d71e732b52f3609feefbc80e07dc7f.png

从控制面板开启WSL功能

40fe9be1ed1e1203f0632c85b65adb76.png

重启后从Windows商店搜索安装Ubuntu,并等待其安装完成

5c47065f14402ac9d33effe4b6d9b2df.png

设置ubuntu默认账户为root (为了更改至Archlinux)

a8d428993816f275ad0c958d927a525e.png Ubuntu安装完成后无需创建用户,到powershell中将默认账户改为root

ubuntu config --default-user root2. 下载Archlinux替换Ubuntu

下载Arch bootstrap.tar.gz至WSL文件系统的/root路径下

Archlinux Download: https://www.archlinux.org/download/

/root path: C:Users[USER_NAME]AppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindows_xxxxLocalStaterootfsroot

更改完默认账户后重新打开bash,以root身份解压Arch Bootstrap.tar.gz

$ tar -zxvf archlinux-bootstrap-xxxx.xx.xx-x86_64.tar.gz

在解压出的root.x86_64文件夹中的etc/pacman.d/mirrorlist中选择适合的服务器取消注释

配置/etc/resolv.conf

$ vim ~/root.x86_64/etc/resolv.conf

# Resolver configuration file.

# See resolv.conf(5) for details.

nameserver 192.168.1.1

nameserver 8.8.8.8

nameserver 8.8.4.4

关闭bash,使用Windows资源管理器在WSL根路径下删除bin, etc, lib, lib64, sbin, usr, var文件夹,并将/root/root.x86_64中的对应文件移动至根路径(是移动不是复制!)

重新打开bash,安装Archlinux

$ pacman-key --init

$ pacman-key --populate archlinux

$ pacman -Syyu base base-devel

创建新用户并设置密码

$ useradd -m -s /bin/bash username

$ passwd root

$ passwd username

在/etc/sudoers中设置sudo权限,如

username ALL=(ALL)

关闭bash,在powershell中设置默认账户为刚刚创建的账户

$ ubuntu config --default-user username3. 配置GUI

为了轻量化与占资源少,选用了xfce4

$ pacman -S xfce4

$ pacman -S xfce4-goodies # optional

安装中文适配(optional)

$ vim /etc/locale.gen

en_US.UTF-8 UTF-8 # 取消注释

zh_CN.UTF-8 UTF-8 # 取消注释

$ locale-gen

$ echo LANG=en_US.UTF-8 > /etc/locale.conf

$ sudo pacman -S wqy-microhei

Windows端架设Xserver,可使用Xming,MobaXterm等软件,选用MobaXterm

https://mobaxterm.mobatek.net

启动MobaXterm,启动Xserver,在要使用GUI的用户的~/.bashrc中配置显示选项

export DISPLAY=:0

启动需要GUI的程序,效果如下

543df56b89d14b400be962fce88c88f4.png4. 优化

在启动文件夹创建使MobaXterm快捷方式,配置开机启动

启动文件夹位于C:UsersusernameAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup

加入-hideterm启动项可以使其在托盘启动

711466512f091d7c86f44c3811a707f6.png

使用xfce4的GUI终端

创建terminal-xfce4.bat

C:WindowsSystem32bash.exe -c "export DISPLAY=:0 && xfce4-terminal"

使用vbs启动bat消除Windows命令行界面,创建一个vbs文件,内容如下

Set shell = Wscript.createobject("wscript.shell")

a = shell.run("C:UsersusernameSoftwarescriptterminal-xfce4.bat", 0)

vbs启动终端效果如下

6810b07ece223e1785ccc452906b1c11.png

项目运行效果

1.png

配置VSCode默认Console为WSL-bash (optional)

在文件>首选项>设置中加入

"terminal.integrated.shell.windows": "C:\Windows\sysnative\bash.exe"

参考资料

Install on WSL (简体中文) - ArchWiki

https://wiki.archlinux.org/index.php/Install_on_WSL_(简体中文)

[HOW-TO] Installing Arch on WSL Manually : bashonubuntuonwindows

https://www.reddit.com/r/bashonubuntuonwindows/comments/5vnne8/howto_installing_arch_on_wsl_manually/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值