iT邦幫忙

2025 iThome 鐵人賽

DAY 29
0

拿到新的電腦,對程式設計師來說,當然就是要來設定開發程式的環境。就照著這些步驟來做吧!

安裝編輯器

找到自己喜歡的編輯器下載並安裝。建議可以從 Visual Studio Code 開始試試看。

終端機

Mac 有內建的「終端機」,也可以用功能更多而且免費的的「iTerm2」

命令列套件管理工具: homebrew

這個是用來安裝及升級各種重要的命令列工具的。到官網 https://brew.sh/zh-tw,複製中間的那行字,貼到終端機上按 [Enter] 。

用 hombrew 安裝好用的命令行工具

以下的指令會安裝這些命令行工具

  • git
  • jq
  • ripgrep
  • fd
  • fzf
brew install git jq ripgrep fd fzf

安裝及設定多語言版本管理工具

當希望專案不會被程式語言升級影響,能長久使用下去時,會需要語言版本管理工具。我們使用 mise 來管理各種語言的版本:

brew install mise

~/.zshrc 裡加上這幾行設定

## 檔案位置在 ~/.zshrc

eval "$($HOME/.local/bin/mise activate zsh)"

用 mise 安裝程式語言

在終端機裡輸入相對應的命令。有 -- 開頭的是註釋,不用輸入。

-- python
brew install uv
mise use -g python@latest

-- JavaScript (Node)
brew install vite
mise use -g node@latest

-- elixir
brew install wxwidgets
mise use -g erlang@latest
mise use -g elixir@latest

安裝 PostgresQL 資料庫

brew install postgresql@14

怎麼讓自己的終端機提示更好用

安裝下列工具

  • eza
  • zoxide
  • zsh-history-substring-search
  • zsh-syntax-highlighting
brew install eza zoxide zsh-history-substring-search zsh-syntax-highlighting

打開編輯器,找到 ~/.zshrc 這個檔案 (如果沒有就開新檔案),並貼上以下內容:

# ls aliases
if command -V eza >/dev/null 2>&1; then
  alias ls="eza --color=always --long --git"
  alias l="eza --git"
  alias ll="eza -alh -F=auto --git"
  alias sl="l"
  alias lt="eza --tree"
  alias llt="eza --tree --long --git"
else
  alias l="ls -CF"
  alias ls="ls -G"
  alias la="ls -al"
  alias ll="ls -alFh"
  alias sl="ls"
fi

# Git 資訊函數
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:git:*' formats '[%b]'
setopt PROMPT_SUBST

# 設定 prompt 為 `~ [git info] $`
PROMPT='%~ ${vcs_info_msg_0_} $ '

# zsh-syntax-highlighting(語法上色)
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# zsh-history-substring-search(搜尋歷史)
source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh

# 綁定上下鍵搜尋歷史
bindkey '^[[A' history-substring-search-up      # 上鍵
bindkey '^[[B' history-substring-search-down    # 下鍵

# 基本歷史設定
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt SHARE_HISTORY

eval "$(zoxide init zsh --cmd cd)"

上一篇
Ch 27. 怎麼用別人做出來的程式
系列文
Just enough code with AI: 給新手們的程式設計世界觀29
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言