一、前言
以前用 Oracle VM VirtualBox,玩 CentOS 7,时不时就卡一些,而且还不流畅(我喜欢平滑顺畅完美);无意中发现了 windows WSL2发布了,感觉很溜啊!内嵌子系统,高大上啊!如果你感兴趣,接着看文章吧。借鉴了很多大佬的经验帖子。
二、基础知识准备
三、坑,很多很多坑,_(´ཀ`」∠)_吐了
3.进入 docker ubuntu后,不要着急下载软件。先去 更换国内源。防止,下错软件版本。以免造成依赖死循环。
4.如果你像我一样,基于下边那个镜像 pull,恭喜,各种命令都没有,ORZ~~~,连 sudo/nano/vi/vim/gcc等也没有。
5.进入 ubuntu后,不要直接装 KDE桌面,没有那么容易(我还没成功);先装个xfce4,兼容性好些,VNC 也可以远程连上。
6.不要轻易执行:docker rm
7.想起来,再补充。
四、WSL2
适用于 Linux 的 Windows 子系统安装指南 (Windows 10)
https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#update-to-wsl-2
安装和设置 Windows 终端
https://docs.microsoft.com/zh-cn/windows/terminal/get-started
Windows Terminal 美化实例
https://zhuanlan.zhihu.com/p/76436374
Windows Terminal 美化主题配色
https://windowsterminalthemes.dev/
1.
2.
3.
4.
5.示例
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"colorScheme": "DimmedMonokai",
"hidden": false,
"useAcrylic": true,
"acrylicOpacity": 0.75
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"colorScheme": "DimmedMonokai",
"hidden": false,
"useAcrylic": true,
"acrylicOpacity": 0.75
},
{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
]
},
"schemes": [
{
"name": "BirdsOfParadise",
"black": "#573d26",
"red": "#be2d26",
"green": "#6ba18a",
"yellow": "#e99d2a",
"blue": "#5a86ad",
"purple": "#ac80a6",
"cyan": "#74a6ad",
"white": "#e0dbb7",
"brightBlack": "#9b6c4a",
"brightRed": "#e84627",
"brightGreen": "#95d8ba",
"brightYellow": "#d0d150",
"brightBlue": "#b8d3ed",
"brightPurple": "#d19ecb",
"brightCyan": "#93cfd7",
"brightWhite": "#fff9d5",
"background": "#2a1f1d",
"foreground": "#e0dbb7"
},
{
"name": "BlulocoDark",
"black": "#4a505d",
"red": "#f81141",
"green": "#23974a",
"yellow": "#fd7e57",
"blue": "#285bff",
"purple": "#8c62fd",
"cyan": "#366f9a",
"white": "#ccd5e5",
"brightBlack": "#61697a",
"brightRed": "#fc4a6d",
"brightGreen": "#37bd58",
"brightYellow": "#f6be48",
"brightBlue": "#199ffd",
"brightPurple": "#fc58f6",
"brightCyan": "#50acae",
"brightWhite": "#ffffff",
"background": "#1e2127",
"foreground": "#abb2bf"
},
{
"name": "DimmedMonokai",
"black": "#3a3d43",
"red": "#be3f48",
"green": "#879a3b",
"yellow": "#c5a635",
"blue": "#4f76a1",
"purple": "#855c8d",
"cyan": "#578fa4",
"white": "#b9bcba",
"brightBlack": "#888987",
"brightRed": "#fb001f",
"brightGreen": "#0f722f",
"brightYellow": "#c47033",
"brightBlue": "#186de3",
"brightPurple": "#fb0067",
"brightCyan": "#2e706d",
"brightWhite": "#fdffb9",
"background": "#1f1f1f",
"foreground": "#b9bcba"
}
],
五、WSL2安装Docker
按照以下2步骤,你就不用担心拉取的镜像,创建的容器占用C盘了。
https://zhuanlan.zhihu.com/p/163763066
WSL2 Docker Distro迁移
https://blog.csdn.net/simongame/article/details/107032441
六、ubuntu18初体验
1.每次,以 root用户身份进入;更改“软件源地址”。
cp /etc/apt/sources.list /etc/apt/sources.list.bak
想要编辑,使用 vim,安装缺提示:E: Unable to locate package vim
https://blog.csdn.net/miss1181248983/article/details/88578287
将 deb http://archive.ubuntu.com/ubuntu/trusty main universe restricted multiverse
这个地址添加到/etc/apt/sources.list
文件中,然后 apt-get update
更新完之后安装就可以了。
echo deb http://archive.ubuntu.com/ubuntu/trusty main universe restricted multiverse >> /etc/apt/sources.list
https://blog.csdn.net/u012308586/article/details/102953882
阿里源:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#更新软件列表,换源完成。就可以安装匹配的想要的各种命令了。
apt-get update
#配置GCC
apt-get install build-essential
2.基于命令行更新软件包的方法
https://blog.csdn.net/davidhzq/article/details/102671746
Ubuntu主要更新升级命令介绍
我们先来看看这几个命令的功能和区别,这几个命令看起来很相似,作用上有较大差别千万不要弄错了。
hzq@ubuntu:~$ sudo apt-get update
[sudo] hzq 的密码:
命中:1 http://mirrors.yun-idc.com/ubuntu xenial InRelease
命中:2 http://mirrors.yun-idc.com/ubuntu xenial-updates InRelease
命中:3 http://mirrors.yun-idc.com/ubuntu xenial-backports InRelease
命中:4 http://mirrors.yun-idc.com/ubuntu xenial-security InRelease
正在读取软件包列表... 完成
hzq@ubuntu:~$
hzq@ubuntu:~$ sudo apt-get upgrade
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
正在计算更新... 完成
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
hzq@ubuntu:~$
hzq@ubuntu:~$ sudo apt-get full-upgrade
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
正在计算更新... 完成
下列软件包是自动安装的并且现在不需要了:
linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
hzq@ubuntu:~$
hzq@ubuntu:~$ sudo apt-get dist-upgrade
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
正在计算更新... 完成
下列软件包是自动安装的并且现在不需要了:
linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
hzq@ubuntu:~$ sudo apt list --upgradable
正在列表... 完成
hzq@ubuntu:~$
hzq@ubuntu:~$ sudo apt-get autoremove
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包将被【卸载】:
linux-headers-4.15.0-45 linux-headers-4.15.0-45-generic linux-image-4.15.0-45-generic
linux-modules-4.15.0-45-generic linux-modules-extra-4.15.0-45-generic snapd-login-service
升级了 0 个软件包,新安装了 0 个软件包,要卸载 6 个软件包,有 0 个软件包未被升级。
解压缩后将会空出 335 MB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 251733 个文件和目录。)
正在卸载 linux-headers-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
正在卸载 linux-headers-4.15.0-45 (4.15.0-45.48~16.04.1) ...
正在卸载 linux-modules-extra-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
正在卸载 linux-image-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-45-generic
/etc/kernel/postrm.d/zz-update-grub:
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.15.0-65-generic
Found initrd image: /boot/initrd.img-4.15.0-65-generic
Found linux image: /boot/vmlinuz-4.15.0-64-generic
Found initrd image: /boot/initrd.img-4.15.0-64-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
正在卸载 linux-modules-4.15.0-45-generic (4.15.0-45.48~16.04.1) ...
正在卸载 snapd-login-service (1.33-0ubuntu0.16.04.1) ...
正在处理用于 dbus (1.10.6-1ubuntu3.4) 的触发器 ...
hzq@ubuntu:~$
sudo apt-get update
sudo apt-get upgrade
sudo apt list --upgradable //如果没有了,就直接重启
sudo apt-get dist-upgrade
sudo reboot
sudo apt list –upgradable //重启之后再看一眼
3.出错、异常处理
apt-get update && apt-get dist-upgrade
Ubuntu下提示E: dpkg was interrupted
mv /usr/bin/localedef /usr/bin/localedef.old
dpkg --configure -a
七、Xfce4 桌面安装
为什么首选它?因为,稳定、兼容性好,又能实现 VNC远程连接,KDE想用,还没成功。
https://blog.csdn.net/fxb163/article/details/84193098
https://cloud.tencent.com/developer/article/1350304
https://www.linuxidc.com/linux/2018-08/153435.htm
在安装Xfce前需要更新一下系统
sudo apt-get update
安装Xfce
sudo apt install xfce4 xfce4-goodies
安装期间好像会出现几次弹窗,让你选择,仔细阅读下英文就理解了。
安装VNC Server
sudo apt-get install vnc4server
启动VNC Server(第一次启动VNC Server时会要求设置密码)
vncserver
另外,还需要修改xstartup文件内容(否则在通过VNC远程连接时会出现灰屏现象)
vim ~/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
按Esc,输入:wq!保存退出。
关闭之前开启的VNC Server窗口
vncserver -kill :1 #注意kill之后有空格
再次启动VNC Server
八、远程连接 VNCSERVER
下载 VNC-Viewer:https://www.realvnc.com/en/connect/download/viewer/