Mac 上开发环境搭建笔记

Mac 使用小技巧

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
# 配置 PD 虚拟机下,走宿主机 SS 代理
宿主机 SS 修改本地 Socks5 监听地址:0.0.0.0
虚拟机网络设置为:桥接
虚拟机的代理为 Socks5 代理:宿主机ip:1086

# 配置终端走代理,返回数据表示成功
export {http,https}_proxy=socks5://0.0.0.0:1086
curl https://www.google.com 

# 显示隐藏文件和隐藏文件
⌘ + ⇧ + .
chflags hidden 文件路径

# Unicode 十六进制输入,⌥ + 对应编码即可
⌘/Command: 2318     ⌥/Alt/Option: 2325  ⇧/Shift: 21E7   ⌃/Control: 2303  
⏎/Enter: 23ce       ⌫/Delete: 232B      ⎋/ESC: 238B    
⇪/Capslock: 21ea    ⇥/Tab: 8677         /Apple Logo: ⌥ + ⇧ + K 

# 截图去掉阴影效果
defaults write com.apple.screencapture disable-shadow -bool TRUE
Killall SystemUIServer

# 关闭 SIP 
⌘ + R 进入恢复模式,终端使用命令 csrutil disable

# 允许任何来源
sudo spctl --master-disable

安装HomeBrew

1
2
3
4
5
6
7
8
9
10
# 安装 Command Line Tools
# https://developer.apple.com/download/more/

# https://brew.sh/index_zh-cn.html
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# 配置 HomeBrew 不自动更新
vim ~/.bash_profile
export HOMEBREW_NO_AUTO_UPDATE=true
source ~/.bash_profile

安装sshpass

1
2
# 安装后可以用 sshpass -p 'PassWord' ssh -p [port] username@host 登陆 ssh。
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

安装telnet

1
brew install telnet

安装adb

1
2
brew tap caskroom/versions
brew cask install android-platform-tools

安装Packet Sender

1
brew cask install packetsender

安装FFmpeg

1
2
# 使用格式 ffmpeg -i input.mov -crf 20 output.mp4
brew install ffmpeg

安装Python3

1
2
brew install python3
python3 --version

安装Git

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
brew install git

# 配置用户名、邮箱
git config --global user.name "your_name" 
git config --global user.email "your_email@youremail.com"

# 查看 Git 配置信息
git config --list

# 生成密钥。在 ~/.ssh 下,id_rsa 是私钥,id_rsa.pub 是公钥。
ssh-keygen -t rsa -C "your_email@youremail.com"

# 设置 Git 为大小写敏感
git init 
git config core.ignorecase false

# 创建一个新仓库
git clone ssh://git@192.168.2.232:10022/streamelody/practice.git
cd practice
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

# 已经存在一个文件夹
cd folder
git init 
git remote add origin ssh://git@192.168.2.232:10022/streamelody/practice.git
git add .
git commit -m "Initail commit"
git push -u origin master

# 已经存在一个仓库
cd repository
git remote rename origin old-origin
git remote add git remote add origin ssh://git@192.168.2.232:10022/streamelody/practice.git
git push -u origin --all
git push -u origin --tags

安装Docker

1
brew cask install docker

使用 Docker 搭建 Gitlab

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
# pull gitlab 镜像
docker search gitlab
sudo docker pull gitlab/gitlab-ce:latest

# ~/.docker/gitlab 下分别创建 config,logs,data 目录
mkdir ~/.docker/gitlab/config
mkdir ~/.docker/gitlab/logs
mkdir ~/.docker/gitlab/data

# 查询本机 ip,在 gitlab 配置文件里指定 external_url 和 gitlab_shell_ssh_port
ifconfig
vim ~/.docker/gitlab/config/gitlab.rb
external_url 'http://192.168.2.232'
gitlab_rails['gitlab_shell_ssh_port'] = 10022

# 创建 docker 中的网络
docker network create gitlab_net

# 启动 Gitlab 容器
docker run --name='gitlab' -d \
       --net=gitlab_net \
       --publish 10022:22 --publish 1443:443 --publish 18080:80 \
       --restart always \
       --volume ~/.docker/gitlab/config:/etc/gitlab \
       --volume ~/.docker/gitlab/logs:/var/log/gitlab \
       --volume ~/.docker/gitlab/data:/var/opt/gitlab \
       gitlab/gitlab-ce:latest
       
# 启动时间较久(大约2分钟), STATUS 显示 healthy 表示启动完成
docker container ls

# 查询本机 ip, 浏览器使用 ip:18080 访问

# 登陆后 Settings -> SSH Keys,添加 SSH Keys
cat ~/.ssh/id_rsa.pub

# 常用命令
docker restart gitlab
docker container stop gitlab
docker container rm gitlab

安装 jekyll

1
2
3
4
5
6
7
8
9
10
gem -v 
sudo gem update --system
sudo gem install -n /usr/local/bin jekyll

# 查看 jekyll 版本
jekyll -v

# 本地预览
cd blog_dir
jekyll serve

安装JDK

1
2
3
4
5
# 安装最新版
brew cask install java
# 安装 JDK 8
brew tap caskroom/versions
brew cask install java8

安装redis

1
2
3
4
5
6
7
8
9
10
11
12
# 安装后配置文件的路径: /usr/local/etc/redis.conf
brew install redis

# 查看安装路径
brew list redis

# 添加至开机启动项(可选)
ln -f /usr/local/Cellar/redis/5.0.3/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

# 启动 
redis-server

安装MySQL 5.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 使用 brew 安装
brew install cmake
brew install mysql@5.5

# 配置环境变量
vim ~/.bash_profile
export PATH="/usr/local/opt/mysql@5.5/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/mysql@5.5/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.5/include"
source ~/.bash_profile 

# 启动mysql服务
brew services start mysql@5.5

# 进入mysql
mysql -uroot

# 修改密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码’);

# 重设密码
mysql_secure_installation

安装Maven

1
2
3
4
5
6
7
brew install maven

# IDEA 中 Maven > Runner > VM Options 设置
-DarchetypeCatalog=local

# Maven home directory
/usr/local/Cellar/maven/3.6.0/libexec

安装Fiddler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 下载并安装 Mono
# https://www.mono-project.com/download/stable/

# 下载 root 证书,存于 Mono 证书库中。
/Library/Frameworks/Mono.framework/Versions/Current/bin/mozroots --import --sync

# 设置环境变量
vi ~/.bash_profile
export MONO_HOME=/Library/Frameworks/Mono.framework/Versions/Current
export PATH=$PATH:$MONO_HOME/bin
source ~/.bash_profile 

# 下载 fiddler-mac.zip
# https://www.telerik.com/download/fiddler

# 解压进入目录,运行
sudo mono --arch=32  Fiddler.exe

IDEA 个性化配置

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
# 打开自动编译
Preferences > Compiler > Build project automatically [勾选]

# 忽略大小写
Preferences > Code Completion > Match case [不勾选]

# 打开智能导包
Preferences > Auto Import
Insert imports on paste: ALL
Add unambiguous imports on the fly [勾选]
Optimize imports on the fly (for current project) [勾选]

# 打开悬浮提示
Preferences > Editor > General
Show quick documentation on mouse move [勾选]

# 设置项目文件编码
Preferences > File Encodings 
Global Encoding: UTF-8 
Project Encoding: UTF-8 
Default encoding for properties files: UTF-8
Transparent native-to-ascii conversion [勾选]

# 取消 Database 字体效果
Preferences > Editor > Color Scheme > Database > Effects [不勾选]