WSL2 Windows Subsystem for Linux

WSL

Windows Terminal

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    // Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions": 
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        // Press Ctrl+Shift+F to open the search box
        {
            "command": "find",
            "keys": "ctrl+f"
        },
        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "ctrl+shift+d"
        },
        {  "command": { "action": "newTab", "index": 2 }, "keys": "ctrl+t" },
        { "command": { "action": "moveFocus", "direction": "down" }, "keys": "ctrl+down" },
        { "command": { "action": "moveFocus", "direction": "left" }, "keys": "ctrl+left" },
        { "command": { "action": "moveFocus", "direction": "right" }, "keys": "ctrl+right" },
        { "command": { "action": "moveFocus", "direction": "up" }, "keys": "ctrl+up" },
        { "command": { "action": "resizePane", "direction": "down" }, "keys": "ctrl+shift+down" },
        { "command": { "action": "resizePane", "direction": "left" }, "keys": "ctrl+shift+left" },
        { "command": { "action": "resizePane", "direction": "right" }, "keys": "ctrl+shift+right" },
        { "command": { "action": "resizePane", "direction": "up" }, "keys": "ctrl+shift+up" },
        { "command": { "action": "closeTab" }, "keys": "ctrl+w" },
    ],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
    "initialCols": 140,
    "initialRows": 35,
    "profiles": 
    {
        "defaults": {},
        "list": 
        [
            {
                "commandline": "powershell.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "commandline": "cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u547d\u4ee4\u63d0\u793a\u7b26"
            },
            {
                "guid": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
                "hidden": false,
                "name": "Debian",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    }

win10 WSL2 开启 systemclt 命令

win10 wsl2开启systemctl命令
修复 "System has not been booted with systemd as init system "的错误。

在这里,如果按照网上的教程,使用 systemctl 命令,如 sudo systemctl start,会失败,得到这样的错误。
System has not been booted with systemd as init system (PID 1). Can't operate.

其原因是,这个 Linux 系统没有 systemd,尽管你使用的是 Debian 、 Ubuntu。这是为什么呢?因为这是 Windows 的 WSL 中的 Lunix,所以系统使用的是经典的 SysV init(sysvinit)系统,所以运行 systemctl 时系统会报错。

如何知道使用的是哪个 init 系统?可以使用命令 ps -p 1 -o comm= 查看与 PID 1(系统上运行的第一个进程)相关的进程名称。

它应该在输出中显示systemd或sysv(或类似的东西)。
如何解决System has not been booted with systemd错误?

sudo apt-get install daemonize
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME

其他

How to Enable SSH on Debian 9 or 10

# update list
sudo apt-get update

# upgrade
sudo apt-get upgrade

# intsall ssh
sudo apt install openssh-server
sudo systemctl status ssh

# install ifconfig
sudo apt install net-tools

# install ping
sudo apt install iputils-ping
sudo setcap cap_net_raw+p /bin/ping

# install git
sudo apt-get install git

# install ZSH
sudo apt install zsh

# intall curl
sudo apt install curl

# intall vim
sudo apt-get install vim

# install ohmyzsh
sudo vim /etc/hosts
# 加上一行
199.232.28.133 raw.githubusercontent.com

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

配置 ohmyzsh

cd ~
vim .zshrc
ZSH_THEME="geoffgarside"

source .zshrc

JAVA

  1. 进入 Oracle 官方网站 下载合适的 JDK 版本。
    注意:需要下载 Linux 版本。我下载的是jdk-11,你下载的文件可能不是这个版本,不过没关系,只要后缀(.tar.gz)一致即可。

  2. 建立 JAVA 目录
    我的放在 /usr/lib/jvm 目录

cd /usr/lib
sudo mkidr jvm
sudo tar -zxvf jdk-11.0.11_linux-x64_bin.tar.gz -C /usr/lib/jvm
  1. 设置环境变量
    修改 ~/.profile 文件,添加
export JAVA_HOME=/usr/lib/jvm/jdk-11.0.11
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

其中 JAVA_HOME 请根据自己的实际安装路径及 JDK 版本配置。

  1. 测试是否安装成功
    java -version

你可能感兴趣的:(WSL2 Windows Subsystem for Linux)