【Linux】在Windows搭建WSL2开发环境

13 篇文章 0 订阅
2 篇文章 0 订阅

WSL安装和调整

这里使用的WSL2,Ubuntu22.04

如果在WSL中需要使用系统代理但是报以下的错:

在这里插入图片描述
在当前Windows用户目录下创建.wslconfig并写入以下配置:

[experimental]
autoMemoryReclaim=gradual  
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

然后重启wsl生效

更改安装位置

首先通过应用商城安装合适的Ubuntu子系统,对应版本会被安装在C盘下,执行下面的操作变更安装路径:
①导出它的备份(比如命名为Ubuntu.tar)

wsl --export Ubuntu-22.04 D:\Ubuntu.tar

②确定在此目录下可以看见备份Ubuntu.tar文件之后,注销原有的wsl

wsl --unregister Ubuntu-22.04

③将备份文件恢复到D:\Ubuntu_WSL中去

wsl --import Ubuntu-22.04 D:\Ubuntu22.04 D:\Ubuntu.tar

在这里插入图片描述
如果你之前有创建默认用户,执行下面的操作设置默认用户:

Ubuntu2204 config --default-user meepo

在这里插入图片描述

变更默认apt源

修改apt源为阿里镜像源,编辑/etc/apt/sources.list文件,更改成下面内容:

deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

不同版本的设置方式参考阿里云镜像站:阿里巴巴开源镜像站

Python环境

变更默认Python版本

添加对应的ppa

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

如果访问慢就修改/etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-jammy.list中的url为清华大学镜像源https://launchpad.proxy.ustclug.org

在这里插入图片描述
删除默认的python3版本:

sudo apt remove python3
sudo apt autoremove

在这里插入图片描述
随后在安装python3.12:

sudo apt install python3.12

在这里插入图片描述
安装完成后我们可以设置下默认python:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1

在这里插入图片描述

安装pip

由于需要连接pypi,先设置一下使用国内镜像:

vim ~/.pip/pip.conf
# 添加以下内容

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com
sudo wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Meepoljd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值