从零开始构建 Linux 开发环境
我的 Linux 配置
一些常用文件的默认位置
zsh 配置文件:~/.zshrc
vscode server:~/.vscode-server
用户配置
创建用户,并授予 root 权限
sudo adduser <user_name>
sudo usermod -aG sudo <user_name>
客户端配置 SSH 免密登录
在客户端 .ssh 目录中,打开 bash 配置私钥
ssh-keygen
将客户端的公钥放到服务端上
cat ~/.ssh/id_rsa.pub | ssh username@ip 'cat >> ~/.ssh/authorized_keys'
⭐ 用 ssh-copy-id 命令更方便(仅限 bash)
ssh-copy-id username@ip
此时,客户端的公钥会被添加到远程服务器上的 ~/.ssh/authorized_keys 文件中
然后就可以使用私钥登录啦~
ssh username@ip [-p port] -i id_rsa
Windows Terminal 配置
字体选择
https://www.nerdfonts.com/font-downloads 随便挑
推荐:
- CaskaydiaCove Nerd Font Mono(或者叫 CaskaydiaCove NFM)
- Hack Nerd Font,选 HackNerdFontMono-Regular.ttf
网络配置
镜像源
可选,未经验证!
备份原有软件源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak_yyyymmdd
修改 sources.list 文件
# 修改为如下地址:
sudo vi /etc/apt/sources.list
# 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
更新系统软件源
# 执行命令,更新系统软件源地址:
sudo apt-get update
sudo apt-get upgrade
# 安装lrzsz tree
sudo apt-get -y install lrzsz tree
# 安装 build-essential 软件包集合 (其中就包括 gcc、G ++ 和 make 等)
sudo apt install -y build-essential
# 安装其他东东
sudo apt install libyaml-dev
代理
WSL
在 Windows 中的 C:\Users<your_username> 目录下创建一个 .wslconfig 文件,然后在文件中写入如下内容
[experimental]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
然后用 wsl --shutdown 关闭 WSL,之后再重启
其他
使用 https://github.com/nelvko/clash-for-linux-install
git clone --branch master --depth 1 https://gh-proxy.com/https://github.com/nelvko/clash-for-linux-install.git \
&& cd clash-for-linux-install \
&& sudo bash install.sh
若使用zsh,则安装完毕后在加入:
source $CLASH_BASE_DIR/script/common.sh && source $CLASH_BASE_DIR/script/clashctl.sh
zsh 配置
更 改默认 shell 为 zsh
# 查看系统当前使用的shell
echo $SHELL
# 如果没有zsh,那就下一个!
sudo apt-get install -y zsh
# 设置默认zsh
chsh -s /bin/zsh
oh-my-zsh 配置
安装 oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装 Powerlevel10k 主题
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.opt/powerlevel10k
echo 'source ~/.opt/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
source ~/.zshrc,就会进入 P10k 的配置界面
若要重置 P10k 配置,运行 p10k configure 或者直接修改 ~/.p10k.zsh
这是手动安装方案,所以不需要在
~/.zshrc里配置ZSH_THEME="powerlevel9k/powerlevel9k"这句话
更改配置文件 .zshrc
vi ~/.zshrc
内容如下:
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
export PATH=$PATH:~/.local/bin/:/snap/bin
# ZSH_THEME="random"
plugins=(
git
extract
rand-quote
themes
z
per-directory-history
history-substring-search
command-not-found
safe-paste
colored-man-pages
sudo
zsh-autosuggestions
# history
zsh-syntax-highlighting
copypath
copyfile
you-should-use
)
source $ZSH/oh-my-zsh.sh
alias :vrc="vi ~/.zshrc"
alias :src="source ~/.zshrc"
alias -s ttt='tar zxvf'
alias cp="cp -i" # 防止 copy 的时候覆盖已存在的文件, 带上 i 选项,文件已存在的时候,会提示,需要确认才能 copy
alias gcm='git checkout master'
# 以自己输入的所有内容为前缀,进行历史查找
bindkey '^P' history-substring-search-up
bindkey '^N' history-substring-search-down
# 让 history 命令显示时间
HIST_STAMPS="yyyy-mm-dd"
bindkey '^H' backward-kill-word
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
source ~/.opt/powerlevel10k/powerlevel10k.zsh-theme
此配置文件会根据文档的进展而逐渐完善
一些插件的下载
zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
zsh-syntax-highlighting
sudo apt install zsh-syntax-highlighting
cd ~/.opt
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
zsh-you-should-use
git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH_CUSTOM/plugins/you-should-use
git 配置
ssh-keygen 一下叭
cd ~/.ssh
ssh-keygen -t rsa
将 id_rsa.pub 公钥内容,添加到 github 之类的托管平台上
设置名字,邮箱
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
设置其他配置项
git config --global core.editor vi
git config --global credential.helper store
Vim 配置
安装 NeoVim
sudo snap install --beta nvim --classic
或者这样
# 不要直接用 apt install neovim,版本很老!
sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install neovim
在 ~/.zshrc 中添加别名,以替换默认的 vim 命令
alias vim='nvim'
alias vi='nvim'
使用个人配置(基于 LazyVim)
git clone git@github.com:Trouvaille0198/neovim-config.git ~/.config/nvim
rm -rf ~/.config/nvim/.git
运行 nvim,等待插件下载完成
若有必要,先删除存在的配置文件和缓存
rm -rf ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim
rm -rf ~/.cache/nvim
添加 snippets
工具安装
snap
包管理器,你总会用到的
sudo apt install snapd -y
deb-get
包管理器,你总会用到的
curl -sL https://raw.githubusercontent.com/wimpysworld/deb-get/main/deb-get | sudo -E bash -s install deb-get
bat
cat 的美化替代品
sudo apt install -y bat
使用软链接
mkdir -p ~/.local/bin
ln -s /usr/bin/batcat ~/.local/bin/bat
==一切的软链接都装在 ~/.local==
并在配置中添加
alias cat='batcat'
eza
ls 的替代品
sudo apt update
sudo apt install -y gpg
sudo mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list
sudo chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
sudo apt update
sudo apt install -y eza
在配置中添加
alias ls='eza'
fd
项目地址:https://github.com/sharkdp/fd
一个命令行搜索工具
sudo apt install fd-find
使用软链接
ln -s $(which fdfind) ~/.local/bin/fd
bashtop
top 的替代品
sudo add-apt-repository ppa:bashtop-monitor/bashtop
sudo apt update
sudo apt install bashtop
或者直接
sudo apt install btop
ifconfig
sudo apt install net-tools
cheat
一本常用命令说明书:https://github.com/cheat/cheat
# cd /tmp \
# && wget https://github.com/cheat/cheat/releases/download/4.4.0/cheat-linux-amd64.gz \
# && gunzip cheat-linux-amd64.gz \
# && chmod +x cheat-linux-amd64 \
# && sudo mv cheat-linux-amd64 /usr/local/bin/cheat
cd ~/.opt \
&& wget https://github.com/cheat/cheat/releases/download/4.4.2/cheat-linux-amd64.gz \
&& gunzip cheat-linux-amd64.gz \
&& chmod +x cheat-linux-amd64 \
&& ln -s ~/.opt/cheat-linux-amd64 ~/.local/bin/cheat
👆 最新版本号随时从官方仓库看
dust
GitHub - bootandy/dust: A more intuitive version of du in rust
du 替代
sudo snap install dust
duf
GitHub - muesli/duf: Disk Usage/Free Utility - a better 'df' alternative
df 替代
sudo apt install duf
gping
gui ping
sudo snap install gping
procs
GitHub - dalance/procs: A modern replacement for ps written in Rust
ps 替代
sudo snap install procs
httpie
curl 替代
sudo snap install httpie
curlie
GitHub - rs/curlie: The power of curl, the ease of use of httpie.
又一个 curl 的替代,保留了 curl 的语法
curl -sS https://webinstall.dev/curlie | bash
zellij
终端管理工具
sudo snap install zellij --classic
使用 alt+d detach,需要修改配置文件
vi ~/.config/zellij/config.kdl
shared_except "locked" {
// ...
bind "Alt d" { Detach; }
}
其他
sudo apt install -y unzip
sudo apt install -y build-essential # gcc etc
sudo apt install -y libedit-dev liblzma-dev libreadline-dev libffi-dev
sudo apt install -y zlib1g zlib1g-dev libssl-dev libbz2-dev libsqlite3-dev