配置本机 Linux 环境
在 windows store 中安装 WSL 以及 ubuntu kernel
WSL 配置
WSL 的默认设置
注意”defaultProfile”以及后面的 terminal 类型数据和机器相关,不能直接覆盖
// This file was initially generated by Windows Terminal 1.4.3243.0// It should still be usable in newer versions, but newer versions might have additional// settings, help text, or changes that you will not see unless you clear this file// and let us generate a new one for you.// To view the default settings, hold "alt" while clicking on the "Settings" button.// For documentation on these settings, see: https://aka.ms/terminal-documentation{"$schema": "https://aka.ms/terminal-profiles-schema","defaultProfile": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}","launchMode":"maximized",// You can add more global application settings here.// To learn more about global settings, visit https://aka.ms/terminal-global-settings// If enabled, selections are automatically copied to your clipboard."copyOnSelect": false,// If enabled, formatted data is also copied to your clipboard"copyFormatting": false,// A profile specifies a command to execute paired with information about how it should look and feel.// Each one of them will appear in the 'New Tab' dropdown,// and can be invoked from the commandline with `wt.exe -p xxx`// To learn more about profiles, visit https://aka.ms/terminal-profile-settings"profiles":{"defaults":{// Put settings here that you want to apply to all profiles."acrylicOpacity":0.7, //背景透明"useAcrylic":true, //启用毛玻璃"fontSize":20,"colorScheme": "Campbell" //配色方案},"list":[{// Make changes here to the powershell.exe profile."guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}","name": "Windows PowerShell","commandline": "powershell.exe","hidden": false},{// Make changes here to the cmd.exe profile."guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}","name": "Command Prompt","commandline": "cmd.exe","hidden": false},{"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}","hidden": false,"name": "Azure Cloud Shell","source": "Windows.Terminal.Azure"},{"guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}","hidden": false,"name": "Ubuntu-20.04","source": "Windows.Terminal.Wsl"}]},// Add custom color schemes to this array.// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes"schemes": [{"name" : "Campbell","cursorColor": "#FFFFFF","selectionBackground": "#FFFFFF","background" : "#0C0C0C","foreground" : "#CCCCCC","black" : "#0C0C0C","blue" : "#0037DA","cyan" : "#3A96DD","green" : "#13A10E","purple" : "#881798","red" : "#C50F1F","white" : "#CCCCCC","yellow" : "#C19C00","brightBlack" : "#767676","brightBlue" : "#3B78FF","brightCyan" : "#61D6D6","brightGreen" : "#16C60C","brightPurple" : "#B4009E","brightRed" : "#E74856","brightWhite" : "#F2F2F2","brightYellow" : "#F9F1A5"}],// 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+shift+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": "alt+shift+d" }]}
配置 Ubuntu 环境
添加普通用户(如已添加普通用户,跳转到下一步配置 sshd)
在 Linux 使用过程中,应尽量避免使用 root 用户直接使用系统,请使用下面的步骤创建一个新用户
- 添加新用户
adduser new_user #根据自己的真实需求修改new_user#这里是创建一个新的用户,用户名不要用new_user
将新用户添加到
sudo组中usermod -G sudo new_user
使用
su命令切换到新用户su - new_user
配置 sshd
- 使用命令
sudo vim /etc/ssh/sshd_config打开 sshd 的配置文件,找到ClientAliveInterval和ClientAliveCountMax并将其修改为(如果没有直接添加即可):
- 重启 sshd 服务
sudo service sshd restart
如果上述命令报错,大致内容为 sshd 这个服务不存在的话,就执行
sudo service ssh restart
zsh 的安装及配置
安装前更新下apt源
sudo apt update
- 安装 zsh
sudo apt install zsh
- 修改默认 shell 为 zsh
chsh -s /bin/zsh
- 安装 oh-my-zsh
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"##如果不成功,请执行下面两条命令,成功了就不需要做下面两条wget 47.93.11.51:88/install_zsh.shbash install_zsh.sh
- 安装 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- 使用命令
vim .zshrc打开.zshrc 文件,找到plugins=()这一行,将 zsh-syntax-highlighting 添加进去
plugins=(git zsh-syntax-highlighting)
- 安装其他插件
##命令自动补全插件mkdir ~/.oh-my-zsh/plugins/incrwget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh##命令自动推荐,根据历史记录git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions##目录自动跳转插件sudo apt install autojump
- 使用命令
vim .zshrc,打开后在最后插入以下内容:
#设置终端颜色,提示符,及上一条指令返回码提示autoload -U colors && colorsPROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%1~ %{$reset_color%}%# "RPROMPT="[%{$fg[yellow]%}%?%{$reset_color%}]"# Useful support for interacting with Terminal.app or other terminal programs[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zshsource /usr/share/autojump/autojump.shsource ~/.oh-my-zsh/plugins/incr/incr*.zsh
注意,复制后可能会因为 Vim 的配置导致以上内容被注释,也就是在前面加上了
#,如果有的话,删掉就行。
配置 Vim(使用新添加的用户操作)
Vim 配置推荐 - ma6174(不用打开这个官方网站)
更新 apt 源信息
sudo apt update
配置 vim,执行下面命令配置安装 vim
wget 47.93.11.51:88/install_vim.shbash install_vim.sh
ctags 安装与配置
- 使用以下命令安装ctags
sudo apt install ctags
- 执行以下命令
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/*
- 使用命令
vim .vimrc编辑.vimrc,在最后添加以下内容
set tags+=~/.vim/systags
安装 glibc-doc
- 使用以下命令安装
sudo apt install glibc-doc
