WSL2配置Distrobox
Published on 2024-05-05 10:16 in 分类: 环境配置 with 真真夜夜
分类: 环境配置

WSL2配置Distrobox

WSL使用教程

产生此想法的考量:

  1. 我使用zerotier内网穿透,每一个WSL2都需要单独的添加进内网中,这很不优雅
  2. 每一个WSL2都需要单独的分配ssh端口,这很不优雅
  3. 每次损坏WSL2都需要完全重新安装,这也很不优雅

由此,我萌生出使用distrobox的想法,因为网上教程足够的多,支持的系统也多(后期我可能会考虑incus)
感谢Ivon大佬的教程

1. 安装distrobox

默认使用的是Docker作为后端

sudo apt install distrobox

当然如果你想,也能够使用Podman作为后端

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/extras/install-podman | sh -s -- --prefix ~/.local

curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --next --prefix ~/.local

之后添加~/.bashrc or ~/.zshrc

# Podman和Distrobox的路径
PATH=$PATH:$HOME/.local/podman/bin:$HOME/.local/bin
# 允许应用程序显示在屏幕上(需安装xhost)
xhost +si:localuser:$USER

2. 创建一个distrobox

distrobox create不加任何参数,默认安装一个最新的fedora

创建一个debian12的distrobox

distrobox create --name debian12 --image debian:12

自定义安装路径

distrobox create --name debian12 --image debian:12  --home ~/distrobox/debian12

设置root权限

distrobox create --name debian12 --image debian:12  --root

添加环境变量

distrobox create --name debian12 --image debian:12  --additional-flags "--env EDITOR=vim"

设定预先要安装的套件

distrobox create --name debian12 --image debian:12 --additional-packages "git tmux vim"

外挂docker volume

distrobox create --name debian12 --image debian:12 --volume /opt/my-dir:/usr/local/my-dir:rw

3. distrobox相关

# 启动
distrobox enter debian12
# 重启
distrobox restart debian12
# 停止
distrobox stop debian12
# 删除
distrobox rm debian12
posted @   真真夜夜  阅读(83)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示