如何快速完成一个电脑的环境安装

背景

新电脑又得配一次环境,每次都比较麻烦,还老是忘这忘那,不如维护好一个文档,后面跟着文档走一次就行了,更好的话可以写个脚本。

softwares

  • git (安装 homebrew 的前提)
    先安装 xcode

  • homebrew

    1
    2
    3
    4
    5
    6
    7
    8
    # https://mirrors.ustc.edu.cn/help/brew.git.html
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
    export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
    export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

    /bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"

  • iterm2
    下载地址: https://iterm2.com/downloads.html

  • zsh && oh-my-zsh

    1
    2
    3
    4
    5
    6
    7
    8
    # zsh
    chsh -s /bin/zsh
    # brew install zsh

    # omz 国内源
    sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

    # 要怎么玩 omz 根据自己需要
  • sshkey

    1
    ssh-keygen -C xxxx@xxx.com
  • gitconfig

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    cat <<eof > ~/.gitconfig
    [user]
    name = zhangsan
    email = zhangsan@xx.com

    [alias]
    a = add
    ps = push
    pl = pull
    cim = commit -m
    b = branch
    co = checkout
    d = diff
    st = status

    eof

  • bash alias

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    # vscode
    alias c=code
    alias c.="code ."

    # git
    # alias g=git
    alias gac="git a . && git cim "
    alias gpl="git pull"
    alias gps="git push"

    # golang
    alias gt="go mod tidy"
    unalias g # for go version tool - g


    # docker cli
    alias lzd=lazydocker

    ##########KUBEALIAS##########
    export KUBE_EDITOR=vim

    alias k=kubectl
    alias ke="kubectl edit"
    alias ked="kubectl edit deploy"
    alias kg="kubectl get"
    alias kgp="kubectl get po"
    alias wp="watch kubectl get po"
    alias kd="kubectl delete"
    alias kdp="kubectl delete pod"
    alias klf="kubectl logs -f"
    alias krrd="kubectl rollout restart deploy "
    ##########KUBEALIAS##########

    alias cdgosrc="cd ~/go/src"
    alias cdcode="cd ~/code/"

  • wget & httpie

    1
    brew install wget && brew install httpie
  • lazydocker

    1
    brew install lazydocker
  • k9s

    1
    brew install k9s
  • golang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 安装 g (多版本管理工具)
    curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
    echo "unalias g" >> ~/.bashrc # 可选。若其他程序(如'git')使用了'g'作为别名。
    source "$HOME/.g/env"

    g ls-remote

    # 安装最新版
    g install stable
  • nodejs

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    # 可以安装 nvm (版本管理)
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

    nvm install stable

    # 或者直接下载:https://nodejs.org/en/download/

    # 安装 yarn
    npm install -g yarn

    # 安装 nrm
    yarn global add nrm

    nrm ls && nrm use taobao

    yarn global add pm2

  • pip config

    1
    2
    3
    4
    5
    6
    7
    8
    mkdir ~/.pip
    cat <<eof > ~/.pip/pip.conf
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

    eof

    pip3 install --upgrade pip
  • glances

    1
    2
    pip3 install --upgrade pip
    pip3 install glances
  • sshw

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # 下载地址: https://github.com/iamlongalong/sshw/releases

    cat <<eof > ~/.sshw
    - name: testgroup
    children:
    - name: testecs
    user: root
    host: xx.xx.xx.xx
    callback-shells:
    - {cmd: 'ls'}
    jump:
    - host: xxx.xxx.xxx.xx
    user: root
    eof

办公常用软件

其他

  • 三指拖动: 启动台 => 设置 => 辅助功能

linux 安装 (debian 10)

linux brew

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 使用中科大源
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"

/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"

# brew 有 root 限制,因此包一层命令
cat <<eof > /usr/local/bin/brew
#!/bin/bash
echo -e "INFO: this is a brew wrapper\n"
cmd="/home/linuxbrew/.linuxbrew/bin/brew $@"
echo "$cmd"
su - huhailong.andy -c "$cmd"

echo -e "\nINFO: finish wrap brew"
eof

chmod +x /usr/local/bin/brew

which brew

brew update

zsh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 安装 zsh
apt-get install zsh

# 切换默认为 zsh
chsh -s $(which zsh)

# 配置 omz
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 在~/.zshrc中,找到plugins这行,改为如下
plugins=(git z extract themes zsh-autosuggestions zsh-syntax-highlighting)

#vim ~/.oh-my-zsh/themes/robbyrussell.zsh-theme (给提示符增加 username@hostname )
PROMPT="%{$fg[green]%}%n%{$reset_color%}@%{$fg[cyan]%}%m %(?:%{$fg_bold[green]%}%1{➜%}:%{$fg_bold[red]%}%1{➜%}) %{$fg[cyan]%}%c%{$reset_color%}"

代码环境

  • python

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    mkdir ~/.pip

    # 配置源
    cat <<eof > ~/.pip/pip.conf
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple

    eof

    # 安装pip
    apt install python3-venv python3-pip

    # 升级
    pip3 install --upgrade pip

    # 安装 glances
    pip3 install glances

    # 安装 pyenv (python 版本管理工具)
    curl https://pyenv.run | bash

    # 加载到 zsh
    cat <<eof >> ~/.zshrc
    eval "$(pyenv virtualenv-init -)"
    eof

    # 加载到 bash
    cat <<eof >> ~/.bashrc
    eval "$(pyenv virtualenv-init -)"
    eof

  • docker

    1
    2
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh

网络环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vim /etc/proxy4chain
// 最后的 socks4 行使用 http, 改成下面的内容
// http 10.8.6.103 8118 // 公司提供的 proxy 地址

cat <<eof > /usr/local/bin/proxy
#!/bin/bash

export http_proxy=http://xxx.xx.xx.xx:8118
export https_proxy=http://xxx.xx.xx.xx:8118
export no_proxy=xxx.xxx.xx

cmd="proxychains4 $@"

$cmd

eof

chmod +x /usr/local/bin/proxy

# 验证一下
proxy curl https://google.com

其他

1
2
3
4
5
go install github.com/spf13/cobra-cli@latest

curl -sLS https://get.arkade.dev | sudo sh

# ark get yq jq

True happiness arises, in the first place, from the enjoyment of oneself, and in the next, from the friendship and conversation of a few select companions.
Joseph Addison


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!