Intern 快速 Landing+环境搭建

item2下载

Mac 终端工具

https://iterm2.com/downloads.html

homebrew下载

Mac 软件包管理工具

https://brew.sh/

brew换国内源:

1
2
3
4
5
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

ohmyzsh配置

ohmyzsh 在插件比较多的情况下加载非常慢,可以考虑使用 zinit 代替

配置可以参考 https://github.com/x893675/dotfiles/tree/master/zsh

安装ohmyzsh:

1
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装常用的插件

1
2
3
4
git clone https://github.com/zsh-users/zsh-completions.git ~/.oh-my-zsh/custom/plugins/zsh-completions
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
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search

配置zshrc(~/.zshrc)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ZSH_THEME="ys"
...
plugins=(colored-man-pages common-aliases docker extract git golang kubectl safe-paste sudo z zsh-autosuggestions zsh-completions zsh-syntax-highlighting zsh-history-substring-search)
autoload -U compinit && compinit
zle -N history-substring-search-up && bindkey "^[[A" history-substring-search-up
zle -N history-substring-search-down && bindkey "^[[B" history-substring-search-down
...
alias proxy_on="export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890"
alias proxy_off="unset http_proxy https_proxy all_proxy"
alias kg='kubectl get'
alias kd='kubectl describe'
alias kl='kubectl logs'
alias ka='kubectl apply -f'
alias ke='kubectl exec -it'
alias kde='kubectl delete'

tmux配置

tmux的配置文件:~/.tmux.conf

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
set -g default-shell /bin/zsh

# use Ctrl+a instead of Ctrl+b
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix

# Set easier window split keys
bind-key v split-window -h
bind-key h split-window -v

# Shift arrow to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window

# Use Alt-arrow keys to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D


# Mouse mode
set -g mouse on

# Set the base index for windows to 1 instead of 0.
set -g base-index 1

# Set the base index for panes to 1 instead of 0.
setw -g pane-base-index 1

# Pane colors.
set -g pane-border-style fg=green
set -g pane-border-style bg=black
set -g pane-active-border-style fg=white
set -g pane-active-border-style bg=black

# set status
set -g status-fg white
set -g status-bg colour234
set -g status-position bottom
set -g status-justify left
set -g status-left '#{?client_prefix,<,[}#[default]#S#{?client_prefix,>,]} '
set -g status-right '%y-%d-%m %H:%M:%S '
set -g message-style fg=colour16
set -g message-style bg=colour221
set -g message-style bold
set -g window-status-current-format "#[fg=colour25,bg=colour39,noreverse,bold] #I #W "
set -g window-status-format "#[fg=white,bg=colour234] #I #W "

# Easy config reload
bind-key r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
# Set synchroinze-panes on
bind-key y setw synchronize-panes on \; display-message "panes sync open"
# Set synchroinze-panes off
bind-key n setw synchronize-panes off \; display-message "panes sync closed"

tmux使用技巧

通过tmux命令打开一个session,并有一个window

然后通过ctrl+a c命令可以打开一个新的window ctrl+a & 关闭当前window

shift+ ⬅️ 切换到左边的window

shift+ ➡️ 切换到右边的window

在一个window内可以通过ctrl+a h进行横向增加pane, ctrl+a v纵向增加pane

ctrl+a+ ⬅️ 切换到左边的pane

ctrl+a+ ➡️ 切换到右边的pane

ctrl+a+ ⬆️ 切换到上面的pane

ctrl+a+ ⬇️ 切换到下面的pane

在一个window中开启所有的pane都执行同一个命令: ctrl+a y

在一个window中关闭所有的pane都执行同一个命令: ctrl+a n

Windows下通过WSL搭建开发环境

通过在Windows中启用WSL,达成类似Linux下开发的效果

  • 安装Docker Desktop
  • 安装VSCode+WSL插件
  • 启用WSL: 通过管理员权限在PowerShell中运行 Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All
  • 对于WSL2,需要下载Linux内核更新包
  • 通过Microsoft Store安装Ubuntu 22.04后并打开
  • 通过Terminal打开WSL窗口后,可直接使用code命令通过VSCode打开文件夹等,也可以通过docker命令与Docker Desktop交互
  • 在WSL中可以通过访问/mnt/c/Users//Downloads访问下载文件

Golang配置

配置Go module代理加速

1
2
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

配置私有Gitlab

1
go env -w GOPRIVATE=gitlab.xxxxx

VSCode插件

  • Go

Ctrl+P > Type “> go install”

image.png

Protoc

  • Linux/WSL, using apt or apt-get, for example:
1
2
sudo apt install -y protobuf-compiler
protoc --version Ensure compiler version is 3+
1
2
brew install protobuf
protoc --version Ensure compiler version is 3+

Kubectl设置自动补全

1
source <(kubectl completion bash)

下载安装4.24.4版本

https://github.com/protocolbuffers/protobuf/releases/tag/v24.4

下载相应系统的包,解压,将 protoc 拷贝到 /usr/local/bin下,include文件夹拷贝到 /usr/local下,默认只能是这个目录,项目中 protoc 没有用 -I 指定 protobuf 的 import 路径,protoc必须与 include包都放在/usr/local下

Python环境

uv配置

image.png

uv 是一个快速的 Python 包管理器和解析器,由 Astral 开发,旨在加速依赖项安装和解决。虽然 uv 主要用于包管理和依赖解析,但它也可以用于创建和管理虚拟环境。

以下是使用 uv 配置 Python 环境的具体步骤:

1. 安装 uv

首先,你需要安装 uvuv 可以通过 pip 安装:

1
pip install uv

2. 创建虚拟环境

uv 可以通过 uv venv 命令创建虚拟环境。默认情况下,虚拟环境会创建在当前目录下的 .venv 文件夹中。

1
uv venv

如果你想指定虚拟环境的路径,可以使用 -p 参数来指定 Python 解释器的路径,或者直接指定虚拟环境的目录:

1
uv venv myenv

这将在当前目录下创建一个名为 myenv 的虚拟环境。

3. 激活虚拟环境

创建虚拟环境后,你需要激活它。激活虚拟环境的方式取决于你的操作系统:

  • 在 Linux/macOS 上:

    1
    source myenv/bin/activate
  • 在 Windows 上:

    1
    myenv\Scripts\activate

激活后,你可以在命令行中看到虚拟环境的名称,表示虚拟环境已经激活。

4. 安装依赖

激活虚拟环境后,你可以使用 uv pip 来安装依赖。uv pipuv 提供的与 pip 兼容的命令,用于安装包。

1
uv pip install <package_name>

例如,安装 requests 包:

1
uv pip install requests

5. 管理依赖

uv 还支持从 requirements.txt 文件中安装依赖。你可以使用以下命令:

1
uv pip install -r requirements.txt

6. 退出虚拟环境

当你完成工作后,可以通过以下命令退出虚拟环境:

1
deactivate

7. 删除虚拟环境

如果你想删除虚拟环境,只需删除虚拟环境所在的文件夹即可:

1
rm -rf myenv

总结

使用 uv 配置 Python 环境的步骤如下:

  1. 安装 uv
  2. 使用 uv venv 创建虚拟环境。
  3. 激活虚拟环境。
  4. 使用 uv pip 安装依赖。
  5. 使用 deactivate 退出虚拟环境。
  6. 如需删除虚拟环境,直接删除文件夹。

uv 提供了快速的依赖解析和安装,适合用于加速 Python 项目的开发和部署。