配置本机 Linux 环境

在 windows store 中安装 WSL 以及 ubuntu kernel
WSL 配置
WSL 的默认设置

注意”defaultProfile”以及后面的 terminal 类型数据和机器相关,不能直接覆盖

  1. // This file was initially generated by Windows Terminal 1.4.3243.0
  2. // It should still be usable in newer versions, but newer versions might have additional
  3. // settings, help text, or changes that you will not see unless you clear this file
  4. // and let us generate a new one for you.
  5. // To view the default settings, hold "alt" while clicking on the "Settings" button.
  6. // For documentation on these settings, see: https://aka.ms/terminal-documentation
  7. {
  8. "$schema": "https://aka.ms/terminal-profiles-schema",
  9. "defaultProfile": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
  10. "launchMode":"maximized",
  11. // You can add more global application settings here.
  12. // To learn more about global settings, visit https://aka.ms/terminal-global-settings
  13. // If enabled, selections are automatically copied to your clipboard.
  14. "copyOnSelect": false,
  15. // If enabled, formatted data is also copied to your clipboard
  16. "copyFormatting": false,
  17. // A profile specifies a command to execute paired with information about how it should look and feel.
  18. // Each one of them will appear in the 'New Tab' dropdown,
  19. // and can be invoked from the commandline with `wt.exe -p xxx`
  20. // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
  21. "profiles":
  22. {
  23. "defaults":
  24. {
  25. // Put settings here that you want to apply to all profiles.
  26. "acrylicOpacity":0.7, //背景透明
  27. "useAcrylic":true, //启用毛玻璃
  28. "fontSize":20,
  29. "colorScheme": "Campbell" //配色方案
  30. },
  31. "list":
  32. [
  33. {
  34. // Make changes here to the powershell.exe profile.
  35. "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
  36. "name": "Windows PowerShell",
  37. "commandline": "powershell.exe",
  38. "hidden": false
  39. },
  40. {
  41. // Make changes here to the cmd.exe profile.
  42. "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
  43. "name": "Command Prompt",
  44. "commandline": "cmd.exe",
  45. "hidden": false
  46. },
  47. {
  48. "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
  49. "hidden": false,
  50. "name": "Azure Cloud Shell",
  51. "source": "Windows.Terminal.Azure"
  52. },
  53. {
  54. "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
  55. "hidden": false,
  56. "name": "Ubuntu-20.04",
  57. "source": "Windows.Terminal.Wsl"
  58. }
  59. ]
  60. },
  61. // Add custom color schemes to this array.
  62. // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
  63. "schemes": [
  64. {
  65. "name" : "Campbell",
  66. "cursorColor": "#FFFFFF",
  67. "selectionBackground": "#FFFFFF",
  68. "background" : "#0C0C0C",
  69. "foreground" : "#CCCCCC",
  70. "black" : "#0C0C0C",
  71. "blue" : "#0037DA",
  72. "cyan" : "#3A96DD",
  73. "green" : "#13A10E",
  74. "purple" : "#881798",
  75. "red" : "#C50F1F",
  76. "white" : "#CCCCCC",
  77. "yellow" : "#C19C00",
  78. "brightBlack" : "#767676",
  79. "brightBlue" : "#3B78FF",
  80. "brightCyan" : "#61D6D6",
  81. "brightGreen" : "#16C60C",
  82. "brightPurple" : "#B4009E",
  83. "brightRed" : "#E74856",
  84. "brightWhite" : "#F2F2F2",
  85. "brightYellow" : "#F9F1A5"
  86. }
  87. ],
  88. // Add custom actions and keybindings to this array.
  89. // To unbind a key combination from your defaults.json, set the command to "unbound".
  90. // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
  91. "actions":
  92. [
  93. // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
  94. // These two lines additionally bind them to Ctrl+C and Ctrl+V.
  95. // To learn more about selection, visit https://aka.ms/terminal-selection
  96. { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
  97. { "command": "paste", "keys": "ctrl+v" },
  98. // Press Ctrl+Shift+F to open the search box
  99. { "command": "find", "keys": "ctrl+shift+f" },
  100. // Press Alt+Shift+D to open a new pane.
  101. // - "split": "auto" makes this pane open in the direction that provides the most surface area.
  102. // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
  103. // To learn more about panes, visit https://aka.ms/terminal-panes
  104. { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
  105. ]
  106. }

配置 Ubuntu 环境

添加普通用户(如已添加普通用户,跳转到下一步配置 sshd)

在 Linux 使用过程中,应尽量避免使用 root 用户直接使用系统,请使用下面的步骤创建一个新用户

  1. 添加新用户
  1. adduser new_user #根据自己的真实需求修改new_user
  2. #这里是创建一个新的用户,用户名不要用new_user
  1. 将新用户添加到sudo组中

    1. usermod -G sudo new_user
  2. 使用su命令切换到新用户

    1. su - new_user

配置 sshd

  1. 使用命令sudo vim /etc/ssh/sshd_config打开 sshd 的配置文件,找到ClientAliveIntervalClientAliveCountMax并将其修改为(如果没有直接添加即可):
    基于 Windows10 的 Linux 开发环境配置 - 图1
  2. 重启 sshd 服务
    1. sudo service sshd restart

如果上述命令报错,大致内容为 sshd 这个服务不存在的话,就执行sudo service ssh restart

zsh 的安装及配置

安装前更新下apt源

  1. sudo apt update
  1. 安装 zsh
  1. sudo apt install zsh
  1. 修改默认 shell 为 zsh
  1. chsh -s /bin/zsh
  1. 安装 oh-my-zsh
  1. sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
  2. ##如果不成功,请执行下面两条命令,成功了就不需要做下面两条
  3. wget 47.93.11.51:88/install_zsh.sh
  4. bash install_zsh.sh
  1. 安装 zsh-syntax-highlighting
  1. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. 使用命令vim .zshrc打开.zshrc 文件,找到plugins=()这一行,将 zsh-syntax-highlighting 添加进去
  1. plugins=(git zsh-syntax-highlighting)
  1. 安装其他插件
  1. ##命令自动补全插件
  2. mkdir ~/.oh-my-zsh/plugins/incr
  3. wget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh
  4. ##命令自动推荐,根据历史记录
  5. git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  6. ##目录自动跳转插件
  7. sudo apt install autojump
  1. 使用命令vim .zshrc,打开后在最后插入以下内容:
  1. #设置终端颜色,提示符,及上一条指令返回码提示
  2. autoload -U colors && colors
  3. PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%1~ %{$reset_color%}%# "
  4. RPROMPT="[%{$fg[yellow]%}%?%{$reset_color%}]"
  5. # Useful support for interacting with Terminal.app or other terminal programs
  6. [ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"
  7. source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
  8. source /usr/share/autojump/autojump.sh
  9. source ~/.oh-my-zsh/plugins/incr/incr*.zsh

注意,复制后可能会因为 Vim 的配置导致以上内容被注释,也就是在前面加上了#,如果有的话,删掉就行。

配置 Vim(使用新添加的用户操作)

Vim 配置推荐 - ma6174(不用打开这个官方网站)

  1. 更新 apt 源信息

    1. sudo apt update
  2. 配置 vim,执行下面命令配置安装 vim

    1. wget 47.93.11.51:88/install_vim.sh
    2. bash install_vim.sh

ctags 安装与配置

  1. 使用以下命令安装ctags
  1. sudo apt install ctags
  1. 执行以下命令
  1. ctags -I __THROW -I __attribute_pure__ -I __nonnull -I __attribute__ --file-scope=yes --langmap=c:+.h --languages=c,c++ --links=yes --c-kinds=+p --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/systags /usr/include/* /usr/include/x86_64-linux-gnu/sys/* /usr/include/x86_64-linux-gnu/bits/* /usr/include/arpa/*
  1. 使用命令vim .vimrc编辑.vimrc,在最后添加以下内容
  1. set tags+=~/.vim/systags

安装 glibc-doc

  1. 使用以下命令安装
  1. sudo apt install glibc-doc