Mac M4 Dev Environment Setup: A Stable and Efficient .zshrc You Can Reuse Long-Term
2/22/2026
In the previous post, Complete Java Setup Guide on macOS (Apple Silicon M Chips), Copy and Run for Beginners, I covered Homebrew + SDKMAN setup. This post focuses on a long-term
.zshrcworkflow for daily development on an M4 Mac.
After the base environment is ready, real productivity comes from reducing repeated command typing.
Common commands many people run every day:
git status
git add .
git commit -m "xxx"
git push
mvn -T 1C spring-boot:run
pnpm dev
Short aliases/functions:
gs
gcm "xxx"
gp
mvnr
pd
That is the core value of .zshrc: configure once, benefit every day.
Principles
- Simple: no heavy framework dependency
- Efficient: optimize high-frequency commands
- Stable: easy to migrate to a new machine
Full .zshrc setup
Open:
vim ~/.zshrc
Basic enhancements
# =====================================
# Basic enhancements
# =====================================
alias ll='ls -lah'
alias ..='cd ..'
alias ...='cd ../..'
alias c='clear'
alias reload='source ~/.zshrc'
Git shortcuts
# =====================================
# Git (merge-based team workflow)
# =====================================
alias gs='git status -sb'
alias ga='git add .'
alias gc='git commit -m'
alias gca='git commit -am'
alias gp='git push'
alias gl='git pull --no-rebase --no-edit'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gb='git branch'
alias glog='git log --oneline --graph --decorate'
gcm() {
git add . && git commit -m "$1"
}
For team repos, merge-based pulls are usually safer by default. Use rebase if that fits your own workflow.
Node / frontend
# =====================================
# Node / frontend
# =====================================
alias dev='npm run dev'
alias build='npm run build'
alias start='npm start'
alias test='npm test'
alias pi='pnpm install'
alias pd='pnpm dev'
alias pb='pnpm build'
Maven (optimized for M4 32GB)
# =====================================
# Maven (optimized for M4 32GB)
# =====================================
export MAVEN_OPTS="-Xms1024m -Xmx4096m -XX:+UseG1GC"
alias mvnr='mvn -T 1C spring-boot:run'
alias mvnp='mvn -T 1C clean package -DskipTests'
alias mvni='mvn -T 1C clean install'
-T 1C runs one build thread per CPU core and usually speeds up builds on Apple Silicon.
Docker
# =====================================
# Docker
# =====================================
alias dps='docker ps'
alias di='docker images'
alias dcu='docker compose up -d'
alias dcd='docker compose down'
alias dcb='docker compose build'
Search enhancements
# =====================================
# Search enhancements
# =====================================
alias grep='grep --color=auto'
Use with rg:
rg "UserService"
rg "interface" --type java
Port handling
# =====================================
# Port handling
# =====================================
killport() {
lsof -ti:$1 | xargs kill -9
}
alias ports='lsof -i -P | grep LISTEN'
alias h='history'
Apply config and daily usage
After saving:
source ~/.zshrc
Or:
reload
Typical usage:
# Frontend
pi
pd
# Backend
mvnr
# Git flow
gs
gcm "fix: update config"
gp
# Port conflict
ports
killport 8080
# Code search
rg "UserService"
Suggested companion tools
- Terminal: Tabby, Ghostty
- IDE: IntelliJ IDEA (Java), VS Code (frontend)
- macOS productivity: Rectangle, Raycast
Summary
This setup removes repetitive command overhead and keeps your flow focused on coding and problem-solving instead of retyping long commands.
Combined with the previous Java environment guide, it forms a practical baseline for most Java + frontend work on macOS M4.