最近由于要部署网站到新服务器,为方便操作要安装一些软件比如vim、ranger、zsh、lazygit。曾经从Ubuntu换到ArchLinux再换到MacOS,期间都是上网搜的教程部署,想着留得青山在,就不怕没柴烧的想法,就部署部署就没了,期间遇到的一些问题和搜到的解决方案也是解决后就扔了,没有记录存档下来。因此最近部署重新安装时又要费时上网搜,于是打算记录一下个人的安装教程,以便后续复用,减少配置环境的时间。
总命令
#!/bin/bash
sudo apt update sudo apt upgrade
need_install(){ sudo apt install nodejs npm tmux nginx -y sudo npm install -g pm2 }
zsh_install(){ sudo apt install zsh git unzip -y chsh -s /bin/zsh curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o install.sh sed -i "73c REMOTE=${REMOTE:-https://gh-proxy.com/https://github.com/${REPO}.git}" install.sh bash install.sh rm install.sh
wget https://gh-proxy.com/https://github.com/dracula/zsh/archive/master.zip unzip master.zip mv zsh-master/dracula.zsh-theme ~/.oh-my-zsh/themes mv zsh-master/lib ~/.oh-my-zsh/themes rm master.zip rm -rf zsh-master git clone https://gh-proxy.com/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone https://gh-proxy.com/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting sed -i "11c ZSH_THEME=\"dracula\"" ~/.zshrc sed -i "73c plugins=( git cp z wd sudo colored-man-pages zsh-autosuggestions zsh-syntax-highlighting web-search extract )" ~/.zshrc }
nvim_install(){ sudo apt-get install software-properties-common sudo add-apt-repository ppa:neovim-ppa/stable sudo apt update sudo apt install -y neovim sudo rm -rf /usr/bin/vi sudo rm -rf /usr/bin/vim sudo ln -s /usr/bin/nvim /usr/bin/vi sudo ln -s /usr/bin/nvim /usr/bin/vim curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://gh-proxy.com/https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim sudo apt install nodejs npm }
lazygit_install(){ LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | \grep -Po '"tag_name": *"v\K[^"]*') curl -Lo lazygit.tar.gz "https://gh-proxy.com/https://github.com/jesseduffield/lazygit/releases/download/v${LAZYGIT_VERSION}/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" tar xf lazygit.tar.gz lazygit sudo install lazygit -D -t /usr/local/bin/ }
yazi_install(){ YAZI_VERSION=$(curl -s "https://api.github.com/repos/sxyazi/yazi/releases/latest" | \grep -Po '"tag_name": *"v\K[^"]*') curl -Lo yazi.tar.gz "https://gh-proxy.com/https://github.com/sxyazi/yazi/releases/download/v${YAZI_VERSION}/yazi-x86_64-unknown-linux-gnu.zip" unzip yazi.tar.gz cd yazi-x86_64-unknown-linux-gnu sudo install ya yazi -D -t /usr/local/bin/ cd .. rm -rf yazi-x86_64-unknown-linux-gnu }
echo "Do you wish to install zsh?" select yn in "Yes" "No"; do case $yn in Yes ) zsh_install ;; No ) ;; esac done
echo "Do you wish to install nvim?" select yn in "Yes" "No"; do case $yn in Yes ) nvim_install ;; No ) ;; esac done
echo "Do you wish to install yazi?" select yn in "Yes" "No"; do case $yn in Yes ) lazygit_install ;; No ) ;; esac done
echo "Do you wish to install ranger?" select yn in "Yes" "No"; do case $yn in Yes ) ranger_install ;; No ) ;; esac done
|
初始化
刚买的服务器首先要更新软件版本信息
sudo apt update
sudo apt upgrade
sudo pacman -Syyu
brew update
brew upgrade
|
zsh
安装
zsh
相比bash
有非常棒的历史命令补全和优化的Tab补全,在输入搜索文件文本命令find . -type f | xargs grep "zsh
时能节省大量时间以及可以按Tab选择补全项。
sudo apt install zsh
chsh -s /bin/zsh
|
重新登录终端即替换成zsh
。
关于zsh
可以修改~/.zshrc
文件。
oh my zsh
安装
oh my zsh
是一个配置zsh
的框架,可以方便设置主题,添加插件等。
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
主题
安装主题dracula
wget https://github.com/dracula/zsh/archive/master.zip unzip master.zip mv dracula.zsh-theme/dracula.zsh-theme ~/.oh-my-zsh/themes mv dracula.zsh-theme/lib ~/.oh-my-zsh/themes rm master.zip rm -rf dracula.zsh-theme
|
编辑~/.zshrc
文件,修改主题为ZSH_THEME="dracula"
插件
oh my zsh
内置挺多插件的,一般用到的如下
plugins=(
git
cp
z
wd
sudo
colored-man-pages
zsh-autosuggestions
zsh-syntax-highlighting
web-search
extract
vi-mode )
|
其中自动补全和语法高亮需要额外下载。
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
|
Vim
安装
一开始用Vim
后来用NVim
,感觉也没太大差别。
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:neovim-ppa/stable
sudo apt update
sudo apt install -y neovim
|
然后把vi
和vim
都删了(
sudo rm -rf /usr/bin/vi sudo rm -rf /usr/bin/vim sudo ln -s /usr/bin/nvim /usr/bin/vi sudo ln -s /usr/bin/nvim /usr/bin/vim
|
插件
vim
推荐用vim-plug
管理插件。
curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
语法高亮用的是coc.nvim
,需要安装nodejs
和npm
sudo apt install nodejs npm
|
编辑~/.config/nvim/init.vim
文件(没有就新建)。
Lazygit
Lazygit
是一个图形化(?但还是键盘操控)的git
。
sudo add-apt-repository ppa:lazygit-team/release sudo apt update sudo apt install lazygit
|
然后终端输入lazygit
就可以打开了
ranger
参考学习博客
终端输入ranger
就可以打开了
然后创建配置文件
编辑~/.config/ranger/rc.conf
个人就修改了几个常用的路径跳转指令
# 74行打开预览图片 set preview_images true
map gd cd ~/Documents map gD cd ~/Downloads map gl cd ~/Documents/Latex map gc cd ~/Documents/Code
|
预览图片需要安装w3m-img
然后添加ranger
的文件图标
git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons echo "default_linemode devicons" >> $HOME/.config/ranger/rc.conf
|
安装highlight
以启动ranger
的代码预览高亮
sudo apt install highlight
|