win10开启内置Ubuntu

文章目录

      • 安装
      • 换源
      • Ubuntu设置中文
      • 添加普通用户
      • 设置默认python版本
      • 安装pip
      • 美化配置

安装

1.打开设置 ->应用 ->应用和功能 ->相关设置 ->程序和功能 ->启用或关闭Windows功能:勾选适用于Linux的Windows子系统,确定,重启电脑
win10开启内置Ubuntu_第1张图片

2.在Windows应用商店里面搜索Linux,安装Ubuntu
3.在应用商店安装Ubuntu之后,在开始菜单中打开Ubuntu,没有图形界面,只有命令行。网上有用 Xming X Server for Windows实现打开Ubuntu图形应用的,但是每次只能打开一个,显示效果也不好

换源

为了能更好地使用win10内置Ubuntu,首先要做的是要给Ubuntu换源,否则下载速度会非常慢。

cd /etc/apt
sudo cp sources.list sources.list.bak
sudo chmod 777 sources.list
sudo vim sources.list
#用#注释掉原先的源,或者ggdG清空文档,复制粘贴如下源:
#阿里云
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

 sudo apt update && sudo apt upgrade


#几份国内的其他源
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# 中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# 163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

Ubuntu设置中文

如果你是刚安装好的系统,先更新一下软件源和软件包,输入
sudo apt update && sudo apt upgrade -y
安装中文语言包:
sudo apt install -y language-pack-zh-hans language-pack-zh-hans-base
设置本地化环境变量:
echo "LANG=zh_CN.UTF-8" >> ~/.profile
重新打开 Ubuntu,完成!
并不是所有命令都支持中文,要看软件是否支持。
如果无效,请参考https://blog.csdn.net/sethqqq/article/details/77017759。

添加普通用户

useradd 用户名 和 adduser 用户名
两个用户创建命令之间的区别
adduser: 会自动为创建的用户指定主目录、系统shell版本,会在创建时输入用户密码。

给普通用户sudo权限,否则用户无法使用sudo命令。
使用root用户编辑/etc/下的sudoers 文件,在文件中添加要创建的用户的sudo权限
win10开启内置Ubuntu_第2张图片

设置默认python版本

whereis python 可以查看系统安装的python程序的位置
进入/etc/bin
ll|grep python 查看本目录下包含python的文件
sudo ln -s python3.5 python 将当前目录下的python3.5可执行程序创建一个名为python的快捷方式
sudo ln -s python3.5 py 创建名为py的快捷方式
以后输入python 或者 py 即可直接进入python3.5

安装pip

pip安装模块的时候会提示找不到pip命令,
whereis pip也找不到
此时执行如下命令:

sudo apt-get purge --auto-remove python3-pip
sudo apt-get update
sudo apt-get -y install python3-pip
此时就安装好了pip3
pip3 list 可以查看当前安装的模块
根据提示pip install --upgrade pip升级pip版本,升级之后,可以直接使用pip命令
如果出现了

Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'
root@wt-pc:/usr/bin# pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'
可能是由于在/usr/bin 目录下创建了pip3的快捷方式引起的导入模块错误,实际上,升级pip之后,会在/usr/local/bin 目录下创建一个pip可执行文件,pip命令就是调用的这个。如果在/usr/bin 目录下创建了pip3的快捷方式会引起引用错误。此时删除这个快捷方式即可(推荐)
或者按照这个方法 如下(不推荐):
将/usr/bin/目录下的pip3文件的

from pip import main 
if __name__ == '__main__': 
     sys.exit(main())
改为:


from pip import __main__ 
if __name__ == '__main__': 
    sys.exit(__main__._main())

美化配置

vim .bashrc
export PS1="\[\e[1;37m\e[1;42m\] \u \!/\# \[\e[1;30m\e[7m\] \[\e[1;47m\]\w \[\e[0m\e[1;30m\e[1;42m\]\[\e[0m\e[0;32m\]\[\e[0m\] "

你可能感兴趣的:(linux)