Mac開發環境部署


1. 安裝 Xcode command line tools

xcode-select --install

2. 安裝 Homebrew

安裝 Homebrew 之前,必須先安裝 Xcode Command Line Tools。

在 terminal 中運行下面的命令,進行 homebrew 的安裝:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

下來,我們需要做一件事讓通過 Homebrew 安裝的程序的啟動鏈接(/usr/local/bin)可以直接運行,無需將完整路徑寫出。通過以下命令將 /usr/local/bin 添加到$PATH 環境變量中:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Cmd+T 打開一個新的 terminal 標簽頁,運行以下命令,確保 brew 運行正常。

brew doctor

安裝完成后,Homwbrew 會將本地 /usr/local 初始化為 git 的工作樹,並將目錄所有者變更為當前所操作的用戶,將來 brew 的相關操作不需要 sudo 。

2.1 配置brew源

因為brew源的問題,可以修改為國內coding源。

cd "$(brew --repo)" && git remote set-url origin https://git.coding.net/homebrew/homebrew.git

cd $home && brew update

2.2 brew 使用命令

安裝一個包,可以簡單的運行:

brew install <package_name>

更新 Homebrew 在服務器端上的包目錄:

brew update

查看你的包是否需要更新:

brew outdated

更新包:

brew upgrade <package_name>

Homebrew 將會把老版本的包緩存下來,以便當你想回滾至舊版本時使用。但這是比較少使用的情況,當你想清理舊版本的包緩存時,可以運行:

brew cleanup

查看你安裝過的包列表(包括版本號):

brew list --versions

3. 使用 Homebrew Cask安裝軟件

為什么使用 Homebrew 安裝軟件?

  1. 步驟簡潔,直接一行命令就可以了。
  2. 方便管理,可以批量進行升級,免去一個個去檢查更新。

3.1 文件預覽插件

有些 插件 可以讓 Mac 上的文件預覽更有效,比如語法高亮、markdown 渲染、json 預覽等等。

brew cask install qlcolorcode qlstephen qlmarkdown quicklook-json qlprettypatch quicklook-csv  webpquicklook #suspicious-package

3.2 常用軟件

# 開發軟件
brew cask install shadowsocksx-ng 
brew cask install iterm2
brew cask install phpstorm	
brew cask install visual-studio-code	
brew cask install sublime-text	
brew cask install atom	
brew cask install sourcetree	
brew cask install filezilla	
brew cask install sequel-pro 
brew cask install dash	
brew cask install typora 

# 下載第三方應用
brew cask install sogouinput	
brew cask install qq 
brew cask install iina	
brew cask install dingtalk	
brew cask install alfred	
brew cask install appcleaner	
brew cask install cheatsheet	
brew cask install onedrive	
brew cask install google-chrome		
brew cask install youdaodict	
brew cask install youdaonote	
brew cask install microsoft-office	
brew cask install snipaste	
brew cask install aliwangwang	
brew cask install mos	
brew cask install jietu	
brew cask install neteasemusic	
brew cask install youku	
brew cask install qqmacmgr	
brew cask install qqlive

# 下載 MAS https://github.com/mas-cli/mas
brew install mas

# 下載 Mac App Store 應用

# 我的賬戶下的應用
mas install 836500024 789066512 409201541  409203825 409183694  724472954 425424353 1153157709  424182884 451108668

mas install 451108668 # qq
mas install 836500024 # wechat
mas install	789066512 # Maipo
mas install	409201541 # Pages 
mas install	409203825 # Numbers
mas install	409183694 # Keynote
mas install	724472954 # Manico
mas install	425424353 # The Unarchiver
mas install	1153157709 # Speedtest 測網速
mas install 424182884 # CHM Reader

# 切換奶牛登錄 MAS 后再在 iterm 中執行下面的
# 奶牛賬戶下
mas install 443987910 972572731 904280696 948079084  453164367 458887729  852320343 1064959555  411643860 1063631769 823528286  955297617 441258766 967805235 1055273043

mas install 443987910 # 1Password
mas install 972572731 # Money Pro
mas install 904280696 # Things
mas install 948079084 # FlashFTP
mas install 453164367 # SystemPal
mas install 458887729 # Translate Tab
mas install 852320343 # Sketch
mas install	954188948 # MWeb
mas install 445189367 # PopClip
# mas install 915542151 # Monity
mas install 1064959555 # NewFileMenu
mas install 411643860 # DaisyDisk 磁盤查看占用
# mas install 975937182 # Fantastical 2 
# mas install	449830122 # HyperDock
# mas install 584653203 # Paw
# mas install 442160773 # Cocoa JSON Editor
mas install 1063631769 # Medis
# mas install 1031280567 # Postico
mas install 823528286 # Folx GO+ 
mas install	955297617 # CodeRunner3 
mas install 441258766 # magnet	窗口管理
mas install 967805235 # Paste
mas install 1055273043 # PDF Expert


# 切換到 Mindnote 賬戶
mas install	1289197285 

3.3 開發環境

# php
brew install php
# mysql
brew install mysql@5.7
# nginx
brew install nginx
# dnsmasq
brew install dnsmasq
# composer
brew install composer
# 也可以使用下面的原始安裝composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# redis
brew install redis

# 安裝 laravel
composer global require "laravel/installer"

# 安裝 valet
composer global require laravel/valet	#確保 ~/.composer/vendor/bin 目錄位於系統的「PATH」中

# 如果報錯執行下面的命令
export PATH="$PATH:$HOME/.composer/vendor/bin"
valet install # 運行 valet install 命令來配置和安裝 Valet 和 DnsMasq,並注冊 Valet 后台隨機啟動。

# 創建工作區
mkdir ~/Codes
cd ~/Codes
valet park

# 如果遇到  Unable to determine linked PHP. 錯誤,執行下面的
brew link --force php@7.1


# 其他開發包安裝
brew install elasticsearch@2.4

echo 'export PATH="/usr/local/opt/elasticsearch@2.4/bin:$PATH"' >> ~/.zshrc    #加入環境變量
/usr/local/Cellar/elasticsearch@2.4/2.4.6/libexec/bin/plugin install mobz/elasticsearch-head   #安裝 head 插件
/usr/local/Cellar/elasticsearch@2.4/2.4.6/libexec/bin/plugin install analysis-kuromoji     #安裝日語分詞
brew services start elasticsearch@2.4    #啟動 elasticsearch2.4

此外你還可以通過 brew cask 安裝 launchrocket,來管理通過 brew 安裝的 service

brew cask install launchrocket

4. iterm2 配置

ZSH安裝可以看這里

# 檢查 zsh 版本
zsh --version
# 檢查終端默認 shell 期待 /bin/zsh
echo $SHELL

可以在安裝homebrew之前,檢查一下zsh的版本,如果版本比較新就不用管,如果比較舊則可以用brew install zsh 安裝一下。

brew install zsh-completions

安裝 oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

如果要使用什么插件,需要在 ~/.zshrc 文件中進行添加。

subl ~/.zshrc

安裝字體

git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh
cd ..
rm -rf fonts

.zshrc 修改代碼。

ZSH_THEME="agnoster"

隱藏前面的主機名,在 .zshrc 下面添加下面的代碼。

prompt_context () { }

隱藏前面的用戶名在 .zshrc 下面添加下面的代碼。

DEFAULT_USER="username"

隱藏第一行

touch ~/.hushlogin
#移除
rm ~/.hushlogin

插件安裝

# 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

plugins=(zsh-autosuggestions zsh-syntax-highlighting)

source ~/.zshrc

5. 終端ss配置

配置 subl命令,使用 sublime 打開文件,也可以使用 ~/.zshrc

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

subl ~/.bash_profile

vi ~/.bash_profile

~/.bash_profile 文件下添加下面的代碼:

export http_proxy=http://127.0.0.1:1087;
export https_proxy=http://127.0.0.1:1087;

下面是定義的開關方法。在終端直接輸入方法名就可以生效。

function ss_off(){
    unset http_proxy  # 如果不想設置方法,則單獨執行這兩句就可以刪除配置的環境變量
    unset https_proxy
    echo -e "已關閉代理"
}

function ss_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:1087" # 這里也是端口號
    export https_proxy=$http_proxy
    echo -e "已開啟代理"
}

刷新環境

source ~/.bash_profile

開啟

ss_off

檢查是否生效

curl ip.cn

關閉 brew 更新

.zshrc 中添加

export HOMEBREW_NO_AUTO_UPDATE=true

6. Git ssh的配置和使用

6.1 設置 Git 的 user name 和 email:(如果是第一次的話)

git config --global user.name "****"
git config --global user.email "***@**.com"

查看配置信息

# 查看本地全局用戶配置信息
git config --global  --list

6.2 生成密鑰

ssh-keygen -t rsa -C "***@**.com"		

6.3 拷貝密鑰到 github

cat ~/.ssh/id_rsa.pub

6.4 測試

ssh -T git@github.com

7. 常用軟件配置

7.1 SS

在偏好配置的網絡接口中 忽略這些主機和域的代理設置 中添加:

127.0.0.1, localhost, 192.168.0.0/16, 10.0.0.0/8, FE80::/64, ::1, FD00::/8,shop.test,box.test,ccshop.test,account.jetbrains.com

這里把本地需要訪問的域名全部加進去,這樣開啟全局的時候就不會走ss。

7.2 PhpStorm

在Github創建一個用於phpstorm配置的倉庫,然后通過下面的方法備份和同步。

File->Settings Repository 中輸入git倉庫地址,然后點擊覆蓋遠程和本地來選擇同步方式。

同步完設置后,安裝常用的擴展包:

  • Laravel Plugin
  • Material Theme UI
  • Translation
  • Dash


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM