目录
Windows10-WSL
Windows Subsystem for Linux(WSL)是一个可以直接执行Linux二进制可执行文件(ELF)的兼容层。和Hyper-v虚拟化不同,WSL是底层把Linux系统调用翻译成Native Windows API。例如安装Ubuntu子系统,就基本可以当作一个Ubuntu系统来用,例如使用Linux Bash,apt-get安装软件,编译和运行Linux程序,文件系统交互等。
-
安装
1. 开启开发者模式
打开 Start->Settings->Update & Security->For Developers,勾选Developer Mode
2. 开启windows子系统功能
打开Control Panel->Programs->Turn windows features on or off,在弹出窗口中勾选Windows Subsystem for Linux
3. 更新Windows,重启
4. 在Microsoft Store中搜索Ubuntu,并安装
-
与Windows10交互
-
可使用tcp通信。例如可以在Ubuntu中安装nginx,可以直接在windows的浏览器中访问http://localhost。
-
文件系统交互。Ubuntu默认把磁盘挂载到/mnt目录下,可以直接cd /mnt/c进入C盘,进而操作文件。
-
设置root密码
#设置root用户
sudo passwd root
# 先输入刚刚设置的用户密码,然后两次输入要设置的root用户密码
安装和配置oh-my-zsh
-
介绍
安装oh-my-zsh首先需要安装zsh。zsh(Z Shell)是一个功能强大的交互式shell脚本命令解释器。它不仅支持bash,还提供一些强大和g高效的功能,例如更好的自动补全和纠错。
-
安装
# 安装 zsh
$ sudo apt-get install zsh
# 查看 zsh 版本
$ zsh --version
# 安装 oh my zsh
$ wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
# 查看所有shell
$ cat /etc/shells
# 查看当前使用bash
$ echo $SHELL
# 切换shell为zsh
$ chsh -s /bin/zsh
# 然后重启
$ reboot
# 建议插件
$ git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
$ vi ~/.zshrc
plugins=(
git zsh-syntax-highlighting zsh-autosuggestions
)
$ source ~/.zshrc
# 修改主题:
$ vim ~/.zshrc
# 修改 ZSH_THEME 值
ZSH_THEME="ys"
# 更新配置
$ source ~/.zshrc
安装fc-cache
sudo apt install fontconfig
更换镜像源
-
Ubuntu配置的默认源并不是国内的服务器,下载更新软件都比较慢,解决下载速度慢问题
-
更换/etc/apt/sources.list文件里的源
# 备份源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
# 编辑sources.list
sudo vi /etc/apt/sources.list
# 刷新列表
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
# 阿里源
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
# 中科大源
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
# 清华源
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
修改主机名
1、查看主机名
在Ubuntu系统中,快速查看主机名有多种方法:
其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后;
其二,在终端窗口中输入命令:hostname或uname –n,均可以查看到当前主机的主机名。
2、临时修改主机名
命令行下运行命令:“hostname 新主机名”
其中“新主机名”可以用任何合法字符串来表示。不过采用这种方式,新主机名并不保存在系统中,重启系统后主机名将恢复为原先的主机名称。
例子:hostname ubuntu-temp
这样主机名字就临时被修改为ubuntu-temp,但是终端下不会立即显示生效后的主机名,重开一个终端窗口(通过ssh连接的终端需要重新连接才可以);
3、永久修改主机名
在Ubuntu系统中永久修改主机名也比较简单。主机名存放在/etc/hostname文件中,修改主机名时,编辑hostname文件,在文件中输入新的主机名并保存该文件即可。重启系统后,参照上面介绍的快速查看主机名的办法来确认主机名有没有修改成功。
值的指出的是,在其它Linux发行版中,并非都存在/etc/hostname文件。如Fedora发行版将主机名存放在/etc/sysconfig/network文件中。所以,修改主机名时应注意区分是哪种Linux发行版。
4、/etc/hostname与/etc/hosts的区别
修改主机名,两个文件都得修改