windows wsl 子系统 debian 安装开发环境 (golang派)
windows 子系统真的方便好用,从此不再需要其他虚拟机软件。要使用 wsl 需要硬件支持,具体的一些安装我忘记了,当时走了一些弯路。
打开 windows 命令窗,运行 wsl 就能查看到帮助,通过运行下面的命令安装 Linux 系统
windows 安装 Debian
wsl --install -d Ubuntu
wsl --install --distribution Debian
我安装的是 debian,如果中途报错,自己解决一下。安装完成后,在运行以下命令就能进入:
debian
此时还不是用 root 登录的,会有很多问题,因此,先退出 debian 系统。在 windows 外的 cmd 窗口运行以下命令,我使用的是 debian,所以:
debian config --default-user root
完成之后再次运行 debian
进入系统。
更新 apt 源,这点最重要了,基本上新系统都要做这一步:
vi /etc/apt/sources.list
# 删除原来的东西
ggdG
# 将这堆粘上去
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
完成后,更新源:
apt-get update
安装下面的经典搭配:
apt install vim
apt install wget
apt install make # 用于 Makefile 文件,用不到的话可以不执行这里
# 添加sbin命令
export PATH=$PATH:/usr/sbin
# 写出时间同步配置文件
echo [Time]>/etc/systemd/timesyncd.conf
echo NTP=ntp1.aliyun.com ntp2.aliyun.com time1.cloud.tencent.com time2.cloud.tencent.com>>/etc/systemd/timesyncd.conf
# 重启时间同步服务
systemctl restart systemd-timesyncd
# 查看时间同步状态
timedatectl timesync-status
# 查看运行状态
systemctl status systemd-timesyncd
安装go语言
我这里安装的是 1.21.1
cd /opt
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz
将其添加到环境变量。
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
完成后保存,执行刷新一下
source /etc/profile
简单配置一下 golang
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go version # 输出 go version go1.21.1 linux/amd64
go语言安装完成了,接着安装 docker
Debian Docker 安装
搭建 docker,根据以下顺序一句句执行即可。
# 创建docker目录
mkdir -p /etc/docker /opt/docker
# 创建docker配置文件
vim /etc/docker/daemon.json
这是我的 docker 配置文件信息
{
"iptables": false,
"graph": "/opt/docker",
"log-driver": "json-file",
"log-opts": {
"max-size": "800m",
"max-file": "50"
},
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
执行以下句子安装
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
sudo usermod -aG docker $USER
安装完成之后 docker 会启动不了,主要是权限问题,参考这里:https://www.golang-mix.com/docker/83 也就是说,cmd 要用管理员命令登录。
安装 docker-compose
声明: 因编程语言版本更新较快,当前文章所涉及的语法或某些特性相关的信息并不一定完全适用于您当前所使用的版本,请仔细甄别。文章内容仅作为学习和参考,若有错误,欢迎指正。
开发者
专题·造轮子
Golang·热门
相关文章