Window10自带的 Linux 子系统 Ubuntu( WSL )

    xiaoxiao2022-07-13  289

                     Window10自带的 Linux 子系统 Ubuntu( WSL )

     

    1、进入 Ubuntu 子系统

    进入子系统的方法,cmd直接输入 bash 就可以了,无需密码直接进入系统了; 也可以直接去Ubuntu应用打开。 2、通过 /mnt/【盘符】/目录 的方式访问Windows目录 试过在Windows的资源管理器中直接对子系统环境目录下的文件所做的修改不能被子系统所识别,因此需要在bash下进行操作。

    3、更换数据源(参考)

    在Ubuntu下我们可以通过 apt-get 命令 很方便的安装/卸载软件,由于默认的软件包仓库是位于国外的,安装软件的时候就可能遇到各种网络问题或者下载到的一些资源不完整,因此就需要切换数据源为国内的镜像站点来改善。 

    # 1.备份原来的数据源配置文件 cp /etc/apt/sources.list /etc/apt/sources.list_backup # 2.编辑数据源配置文件 vi /etc/apt/sources.list

     在这里我使用的是阿里云的数据源:

    deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

      更新配置的命令

    apt-get update

    注:14986版之后更新了内核,第三方的镜像站可能找不到软件包资源,需要切换回官方的源。经测试中科大的源可用

    deb https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

    4、输入以下命令,为 root 用户设置密码:

    $ sudo passwd root

     

    5、创建新用户,命令中 username 替换成你想用的用户名:

    $ sudo adduser username

     6、更新软件

    更新软件源中的所有软件列表:

    $ sudo apt-get update

    更新软件:

    $ sudo apt-get upgrade

    apt-get作为包管理器,其实类似于咱们在windows上使用的软件管家类的软件。

    当运行apt-get update命令的时候,实际上相当于软件管家的“查找更新”操作。它会同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引信息(软件包的版本信息、系统要求、翻译、依赖关系等等)。

    当运行apt-get upgrade命令的时候,实际上相当于软件管家的“一键更新”操作。它会对已经安装有更新的软件进行自动升级。由于确定要更新的软件包需要对本地安装的版本和列表的版本进行比较,所以要在update以后运行这一条。 总而言之,update是更新软件列表,upgrade是更新软件。 更新系统版本:

    $ sudo apt-get dist-upgrade

    下载中文语言包:

    $ sudo apt-get install language-pack-zh-han*

    7、cmd终端 可以使用wslconfig命令进行管理

    1)  设置默认运行的linux系统

    wslconfig /setdefault <DistributionName>

    正如上面所说,如果执行wslconfig /setdefault ubuntu,那么执行bash命令则会运行ubuntu  

    2)卸载linux系统

    wslconfig /unregister <DistributionName>

    当系统出现问题,我们可以卸载后重新安装。如:wslconfig /unregeister ubuntu  

    3) 查看已安装的linux系统

    wslconfig /list

    8、设置默认登陆用户

    当我们运行WSL时,它会用第一次运行时输入的用户名登陆,如果想改为其他用户,可以(以ubuntu为例):

    ubuntu config --default-user root

    这样,以后再运行ubuntu它就会默认以root登陆。此外还可以“ubuntu /?”查看其更多使用方法。 9、安装python版本为2.7(安装之前已经存在python3的版本)

    sudo apt install python

    10、安装 C/C++ 开发环境

    安装编译工具包:

    $ sudo apt-get install build-essential

     

    最新回复(0)