Configuration on Windows WSL

Notes includes Windows subsystem Linux, VMWare Virtual machine, remote cloud and dual system.

WSL Initialization

Before starting everything, make sure your Windows version support WSL function and enable it.
preconfig
(Also, you can use Powershell to enable it. the powershell command is Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux)

Enter Microsoft Store and find a Linux distribution install, and then launch it then you will see (You can either click the software icon in start menu, or just open a cmd/powershell and type bash or wsl)
first launch

If you don’t want to stay in cmd or powershell, just use wsl [Linux command] as an interface.

1
2
~$ cat /proc/version
~$ cat /etc/os-release

to see the system version or use lsb_release -a for Ubuntu.

System configuration

check for updates

1
sudo apt update -qq

set root pass

1
sudo passwd root

对于Server用户, 可能会出现没有通过认证的情况. 解决办法参考这篇文章: https://www.codevoila.com/post/26/fix-authentication-token-manipulation-error-when-changing-user-password-in-ubuntu

Access Windows Files

under /mnt/

It’s more convinient to setup a symbolic link

1
2
ln -s /mnt/c/Users/Shane/Downloads/
ln -s /mnt/c/Users/Shane/Documents/

static network config for Ubuntu 18.04 LTS

/etc/netplan/50-cloud-init.yaml

1
2
3
4
5
6
7
8
9
network:
ethernets:
enp1s0:
addresses: [192.168.122.168/24]
dhcp4: false
gateway4: 192.168.122.1
nameservers:
addresses: [192.168.122.1, 114.114.114.114]
version: 2
1
sudo netplan apply

static network config for Ubuntu 14.04 LTS

edit /etc/network/interfaces

Ubuntu socks5 proxy setting

1
sudo apt-get install tsocks

edit /etc/tsocks.conf

1
2
3
4
5
6
7
8
local = 192.168.122.0/255.255.255.0
local = 10.0.0.0/255.0.0.0

server = 192.168.122.1
# Server type defaults to 4 so we need to specify it as 5 for this one
server_type = 5
# The port defaults to 1080 but I've stated it here for clarity
server_port = 1080
1
2
sudo -s
tsocks apt-get install -y package-name

Install vim

1
2
sudo apt install vim
sudo apt install vim-gnome

我们需要从VIM中将内容复制到系统剪切板里, check

1
vim --version

查看clipboard前面是否有+号. if true, then use "+y for yank and "+p for paste.

更改默认镜像源(Optional, for users suffering slow update speed)

备份系统原镜像源

如果在安装的时候选择的区域为中国,那么默认镜像源是阿里云,也可以改为其他的,比如学校教育网连接清华的软件源速度也是不错的。修改文件在/etc/apt/sources.list中,修改之前记得先备份。

1
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

/etc/apt/sources.list

1
2
3
4
5
6
7
8
9
10
11
12
13
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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

VMWare users: 安装 open-vm-tools

VMWare 官方建议用以替代 vmware tools,

1
2
3
sudo apt install open-vm-tools
sudo apt install open-vm-tools-dev
sudo apt install open-vm-tools-desktop

也可以手动安装. 下载网址:https://github.com/vmware/open-vm-tools
在root用户下运行vmware-install.pl,然后疯狂地回车。
参见网址:https://kb.vmware.com/s/article/2073803

配置PuTTY登陆(For linux server users, not for WSL)

1
2
sudo apt install net-tools
sudo apt install openssh-server

一般ssh就会启动,可以使用命令

1
sudo ps -e |grep ssh

查看。
若没有开启,输入

1
sudo service ssh start

开启。

产生密钥对

Create the pair of key on local computer by the command ssh-keygen -t rsa. Then a directory ‘~/.ssh’ will be found with files ‘id_rsa’ and ‘id_rsa.pub’.

PuTTY client on windows

After you get an SSH private key from Ubuntu server:

  1. Open PuTTYGen and load our private key.
  2. Choose “Save Private Key” as a .ppk file and then close PuTTYGen.
    private-key
  3. enter Connection > Data > Auto-login username, then input your username.
    data
  4. Go to Connection>SSH>Auth, browse your private key for authentication.
    key
  5. Don’t forget to go back to Session>Save
    save

设置共享文件夹(For VMWare users, not for WSL)

首先在VMWare中设置共享文件夹,然后再虚拟机上运行下面的命令就能看到共享文件夹名了。

1
vmware-hgfsclient

进入/etc/systemd/system目录

1
sudo vi /etc/systemd/system/mnt.hgfs.service

添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[Unit]

Description=Load VMware shared folders

Requires=vmware-vmblock-fuse.service

After=vmware-vmblock-fuse.service

ConditionPathExists=.host:/

ConditionVirtualization=vmware


[Service]

Type=oneshot

RemainAfterExit=yes

ExecStart=

ExecStart=/usr/bin/vmhgfs-fuse -o allow_other -o auto_unmount .host:/ /mnt/hgfs

[Install]

WantedBy=multi-user.target

保存后使能这个service

1
sudo systemctl enable mnt.hgfs.service

如果没有创建sudo mkdir -p /mnt/hgfs文件夹,需要创建

1
sudo mkdir -p /mnt/hgfs

重启后检查共享目录是否已经挂载到/mnt/hgfs目录下.

与 Windows 时间同步(For BiSystem users)

只对于硬盘安装的双系统来说,会有这个问题。注意Linux是否遵循UTC时间的这个问题。UTC是世界标准时,如果系统遵循这个时间,那么获取BIOS的时间后,会在实际显示时根据所在时区进行相应计算调整。如果不遵循UTC,那么系统显示时间直接就是BIOS的时间。对于虚拟机系统一般没有这个问题。如果出现问题,解决办法如下:

1
2
sudo apt install ntpdate
sudo ntpdate time.windows.com

这样就设置为和Windows时间一样了。然后再将统一后的时间更新到BIOS固件上:

1
sudo hwclock --localtime --systohc

中文输入法(For Chinese-typing users)

如果安装的是虚拟机系统并且能登陆谷歌,中文输入法不太必要。如果只有一个操作系统有安装中文输入法的必要,建议首先在右上角的System Settings > Region & Language > Input Sources 中加入Chinese。然后点击 Manage installed languages 按钮,系统就会自动安装相应的语言包和输入法了。输入法系统默认是IBus(Intelligent Input Method),也可以选择XIM(搜狗输入法)。但是,安装了中文输入法后很可能会出现卡机的情况,这可能是个系统的bug。

关闭sudo密码(For lazy users)

1
sudo visudo

进入nano编辑器,找到

1
%sudo ALL=(ALL:ALL) ALL

修改为不需要密码

1
%sudo ALL=(ALL:ALL) NOPASSWD:ALL

然后就可以保存退出了(Ctrl+x)

Modifying rm command(Optional)

rm is a really really dangerous command for UNIX-like systems. Luckily, we may modify this command to let it not directly delete one file but move it to the trash where the location in Ubuntu Desktop System is ~/.local/share/Trash.

sudo apt install trash-cli
vi ~/.bashrc

add alias rm="trash" to the end, then :wq. After restart a new terminal, you can directly use rm file or rm directory to move the file to the trash. (Note: If you add after .profile file, it will take effect only once even if you source it. )

Command line enhancing

Hyper

install Hyper on your Win10, and change the default shell to wsl shell: 'C:\\Windows\\System32\\bash.exe' on file ‘.hyper.js’.
and set shellArgs: ['~'] for starting default at WSL $HOME directory.

添加右键使用 WSL 打开

打开注册表,新建 \HKEY_CLASSES_ROOT\Directory\Background\shell\WSL

在WSL下新建command将bash的运行路径添加进去
regedit

可以在WSL下添加一个Icon的字符串值,将图标路径加入进去
icon

不需要的时候,将WSL文件夹删除就好了(其实在文件管理器的地址栏输入bash,cmd或powershell就能在当前路径下进入对应的终端)

桌面系统增强

奇怪的中文字体

下载安装开源的文泉字体系.
如果遇到中文显示为日文字形的,是因为没有配置字体显示优先级。
/etc/fonts/conf.d/etc/fonts/conf.avail~/.config/fontconfig/conf.d 文件夹下新建 64-language-selector-prefer.conf
里面配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>sans-serif</family>
<prefer>
<family>Noto Sans CJK SC</family>
<family>Noto Sans CJK TC</family>
<family>Noto Sans CJK JP</family>
</prefer>
</alias>
<!--以上为设置无衬线字体优先度-->
<alias>
<family>monospace</family>
<prefer>
<family>Noto Sans Mono CJK SC</family>
<family>Noto Sans Mono CJK TC</family>
<family>Noto Sans Mono CJK JP</family>
</prefer>
</alias>
<!--以上为设置等宽字体优先度-->
</fontconfig>

安装Gnome Tweak Tool

这是一个基本的增强工具,比如启用“单击时最小化”(Minimize on click)就可以直接在Tweak中设置

安装命令

1
2
sudo apt install gnome-tweak-tool
sudo apt install gnome-shell-extensions

设置Docker

Dock就是Ubuntu下的菜单栏。Settings下面有一些基本的设置,如果想进一步设置,需要安装

1
sudo apt install dconf-tools

再命令行中输入dconf-editor打开配置编辑,然后进入
org->gnome->shell->extensions->dash-to-dock进行更加细节化的修改,我这里修改了一个最大化时全屏:
autohide-in-fullscreen
当然,所有的设置都可以通过命令来完成。下面的命令将会把Dock变成MacOS类似的底部居中形式

1
2
3
4
5
gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false
gsettings set org.gnome.shell.extensions.dash-to-dock dock-position BOTTOM
gsettings set org.gnome.shell.extensions.dash-to-dock transparency-mode FIXED
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 64
gsettings set org.gnome.shell.extensions.dash-to-dock unity-backlit-items true

如果想回到原来的状态,通过gsettings reset命令,比如下面命令将Dock大小重置

1
gsettings reset org.gnome.shell.extensions.dash-to-dock dash-max-icon-size
1
sudo apt install gnome-shell-extension-dashtodock

GNOME Tweak Tool > Extensions > Dash to Dock > Appearance

设置窗口按钮位置为左上角

打开dconf-editor org–>gnome–>desktop–>wm–>preferences–>button-layout 改为
‘close,minimize,maximize:’

Minimize single window applications on click

‘’’
gsettings set org.gnome.shell.extensions.dash-to-dock click-action ‘minimize’
‘’’
or set in Tweak Tool

安装多媒体编解码器(Codecs)

1
2
3
sudo dpkg --configure -a
sudo apt install libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
sudo apt install ubuntu-restricted-extras

编程环境搭建

C/C++

1
2
3
sudo apt install build-essential
sudo apt install cmake
sudo apt install gdb

Python环境的安装

1
sudo apt install python3 python3-pip

Install numpy for system

1
2
sudo apt install python3-scipy
sudo apt install python3-numpy

使用国内镜像源

Python3 pip使用国内镜像源:新建~/.pip/pip.conf

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

或者在安装时加入

1
-i https://pypi.tuna.tsinghua.edu.cn/simple

OpenCV

https://docs.opencv.org
choose the version that you’ve downloaded. for unzip, install unzip or 7zip.

If there is error like “E: Unable to locate package libjasper-dev”. Use these commands to search and select the correct name:

1
2
3
4
sudo apt update -qq
sudo apt-cache search [package name]
sudo apt-cache show [the right package name]
sudo apt install [package] -y

cmake for supporting gstreamer

1
2
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_GSTREAMER=ON ..

Texlive

1
sudo apt install texlive-full

GNUPlot

http://www.gnuplot.info/

Deep Learning

Miniconda

1
2
~$ sudo apt install bzip2 -qq
~$ bash Directory/of/miniconda/install/file

If you choose not to initialize Miniconda3 in your ~/.bashrc(which will override system python), you can do it yourself by adding export PATH="~/miniconda3/bin:$PATH" to .bashrc of your home directory. Then reopen your terminal.

Opencv for Python

1
2
conda install -c menpo opencv
sudo apt install ffmpeg libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg libavcodec-extra libavdevice-extra libavfilter-extra libavformat57 libavutil56 libpostproc55 libswscale5 ttf-mscorefonts-installer icedtea-plugin # 安装视频编解码器

Jupyter notebook

1
conda install jupyter

PyTorch

https://pytorch.org/get-started/locally/

matplotlib

1
pip install matplotlib

另参考:
https://linuxconfig.org/things-to-do-after-installing-ubuntu-18-04-bionic-beaver-linux

Algebra | 共轭转置与 Hermite 矩阵 Linux command of the day

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×