macbook快速安装配置homebrew/iterm2/oh-my-zsh/vscode/github

配置MacBook


程序员配置MacBook,亲测有效,快速下载安装配置homebrew&iterm2&oh-my-zsh&Vscode+终端+python+cpp+代码格式化&github+终端

ps:有序号123的全是任选其一,【】中的内容需要替换,xxx是自定义名称,代码在终端中运行。

Homebrew

下载安装homebrew

  1. 官网,安装慢(我没成功)
    https://brew.sh
    命令会更新,目前命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. 安装较慢
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. 安装较慢(如果有些奇奇怪怪的报错,比如连接不上可以尝试下这个,亲测有效)
    https://github.com/Cxiaoxing/anything/blob/master/brew_install.rb
ruby /Users/“你的用户名”/Downloads/brew_install.rb
  1. 安装较快
    第一步:创建文件夹
sudo mkdir sudo chown -R $(whoami) /usr/local/bin /usr/local/etc /usr/local/Cellar /usr/local/opt /usr/local/share /usr/local/Frameworks /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/var
sudo mkdir /usr/local/Homebrew  /usr/local/var/Homebrew // (这两个文件夹如果已经存在先删除)

第二步:git克隆(任选其一)
(1) 中科大

sudo git clone https://mirrors.ustc.edu.cn/brew.git /usr/local/Homebrew

(2) 阿里云

sudo git clone https://mirrors.aliyun.com/homebrew/brew.git /usr/local/Homebrew

(3) 清华

sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git /usr/local/Homebrew

第三步:创建一个快捷方式到/usr/local/bin内

sudo ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew

第四步:创建文件夹 并 再次git克隆
(1)中科大

sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone https://mirrors.ustc.edu.cn/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone https://mirrors.ustc.edu.cn/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

(2)阿里云

sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone https://mirrors.aliyun.com/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

(3)清华

sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts
sudo mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-drivers
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts
sudo git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-drivers

第五步:获取权限 并 运行更新

sudo chown -R $(whoami) /usr/local/Homebrew /usr/local/var /usr/local/bin /usr/local/etc /usr/local/Cellar /usr/local/opt /usr/local/share /usr/local/Frameworks /usr/local/include /usr/local/lib /usr/local/sbin
brew link pkg-config 
brew update

第六步:最后设置
// 设置环境变量

vim ~/.bash_profile
把 export PATH=/usr/local/bin:$PATH 加到打开的文件里
source ~/.bash_profile

(1)中科大

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc 
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile

(2)阿里云

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc 
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile

(3)清华

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc 
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile

重启终端,ok了

替换默认源

如果选择了以上方法中前3种,后期下载速度慢的话(肯定的),可以替换默认源,以下三种方法选其一
1、替换为中科大镜像源

// 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
// 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
// 替换homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
// 应用生效:
brew update
// 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

2、替换为阿里镜像源

// 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
// 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
// 应用生效:
brew update
// 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

3、替换为清华镜像源

// 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
// 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
// 替换homebrew-cask.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
// 应用生效:
brew update
// 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles'>> ~/.zshrc
source ~/.zshrc

常用命令推荐:

  • brew install 【插件名】 # 安装插件/字体/软件包等,比如wget
  • brew cask install 【软件名】 # 安装软件,比如python
  • brew uninstall 【想要卸载的插件/软件等】 # 卸载
  • brew search 【想要下载的插件/软件等】 # 查询
  • brew update ; brew cask upgrade # 更新所有用 brew 安装的软件
  • brew list # 显示所有用brew安装的插件/软件等

Iterm2

下载安装iterm2

  1. 已安装homebrew
brew cask install iterm2
  1. 官网
    https://iterm2.com

Oh my zsh

下载安装oh-my-zsh

  1. 已安装curl
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  1. 已安装wget
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

3、官网
https://ohmyz.sh

如果报错类似Failed to connect to raw.githubusercontent.com port 443: Connection refused

在网址https://www.ipaddress.com 中查询报错的链接(例如:raw.githubusercontent.com)的IP

open ~/etc

将此文件夹中hosts复制到桌面
修改桌面上的hosts文件,把 【查到的IP地址 对应的链接】加到最后
(例如:199.232.68.133 raw.githubusercontent.com)
用桌面上的hosts覆盖/etc文件夹里的
重新输入命令

配置oh-my-zsh主题

// 打开配置文件:
vim ~/.zshrc

输入e进入编辑模式
输入i进入insert状态
更改主题找到ZSH_THEME=‘’xxx’’
按esc键,输入 :wq 再按回车键

// 刷新:
source ~/.zshrc

zsh主题推荐:

  • random 每次都不一样,遇到喜欢的就可以输入$ echo $ZSH_THEME查看主题名字
  • muse 简洁明了,这类似的很多可以自己找
  • adben 有明显每次命令起始结束符号,还有时间
  • amuse 有时间,明显起始符号,能看到当前文件路径,较简洁
  • ys 时间,明显起始符号,能看到当前文件路径,较花里胡哨

配置oh-my-zsh插件

// 查看插件:
ls ~/.oh-my-zsh/plugins
// 打开配置文件
vim ~/.zshrc

找到plugins,就是已开启的插件
把想要开启的插件加在后面,插件之间以空格隔开

// 刷新:
source ~/.zshrc

Vscode

下载安装Vscode

  1. 已安装homebrew
brew cask install visual-studio-code
  1. 官网
    https://code.visualstudio.com

vscode4个推荐插件:

  • Chinese
    设置中文页面
  • Eva theme
    设置主题
    我觉得 Eva dark比较好看
    想要其他主题可以上网搜搜 或者 插件里搜theme一个个点看喜欢哪个
  • Material Icon Theme
    文件夹图标会很好看
  • Code runner
    代码片段运行
    支持很多种编程语言
    一个文件超多代码,只想测试其中一小段代码的时候就可以用

配置Vscode+终端

vscode中快捷键shift+command+p打开命令面板
输入install ‘code’ command in PATH并执行
就可以在终端打开Vscode了

// 打开vscode:
code 或者 code .
// 用vscode打开xxx.json:
code xxx.json

配置Vscode+python

下载安装python
  1. 已安装homebrew
brew cask install python
  1. 官网
    https://www.python.org/getit/
下载安装Pip
  1. Python2.7
sudo easy_install pip
  1. Python3
curl https://bootstrap.pypa.io/get-pip.py | python3
// 查看是否成功安装 pip:
pip3 -V
// 更新pip:
pip3 install --upgrade pip
// 安装pylint 检查代码异常:
pip3 install pylint
Vscode内配置python

安装插件python
打开随便一个文件夹
新建文件xxx.py
就可以写代码运行了
(左下角可以换python版本)

创建python虚拟环境

// 版本号自定,我的是3.8

python3.8 -m venv .xxx

这个文件夹下就有名称为xxx的虚拟环境了
应用到当前文件夹:
弹窗选择yes 或者 窗口左下角选择 或者 .vscode中的setting文件里手动修改

配置Vscode+c++

下载插件c/c++
打开随便一个文件夹
直接新建xxx.cpp写代码

配置别的语言类似不写了

配置Vscode+微信开发者工具

打开微信开发者工具
随便新建一个项目
将模拟器独立出来
打开Vscode
下载插件minapp
打开【刚刚新建的项目】文件夹
写代码

插件推荐:

  • wxapp-helper 模版,新建页面的时候自动创建js,json,wxml,wxss文件,初始文件内容也可自定义

代码格式化

快捷键 option+shift+f
第一次提示安装autopep8,点击安装就好

git&github+终端

创建一个空的代码仓库

cd 【自己创建的工程文件夹路径】
git init
// 显示隐藏文件夹:
defaults write com.apple.finder AppleShowAllFiles YES

将访达重启

git config user.name 【你的github用户名】
git config user.email 【你的github登陆邮箱】

在github上创建一个项目
填上项目名称和描述
按需选择公共(免费)和私有(收费)
勾选创建README文件
下拉框gitignore: iOS 选择 Objective-C
下拉框license: 一般选择Apache License 2.0

把自己的key添加到github里
点头像
点击settings
点击SSH and GPG keys

如果没有key
点击New SSH keys,不要关当前网页

ssh-keygen -t rsa -C 【你的github邮箱】

按一路回车键直到生成ssh-key

open ~/.ssh

用文本编辑器打开id_rsa.pub
全部复制
粘贴到刚刚的网页中,并取个名字,创建

上传文件到github

git add “要上传的文件名”
git remote add origin git@github.com:【你的github用户名】/【创建的项目名】.git
// 把远程仓库和本地同步,消除差异:
git pull origin master --allow-unrelated-histories
// 上传(可撤销):
git commit -m 【注释】
// 上传到远程
git push --set-upstream origin master

常用命令推荐:

  • git add # 跟踪新文件
  • rm *&git rm # 移除文件
  • git rm -f # 移除文件
  • git rm --cached # 取消跟踪
  • git mv file_from file_to # 重命名跟踪文件
  • git log # 查看提交记录
  • git commit # 提交更新
  • git commit -m ‘message’
  • git commit -a # 跳过使用暂存区域,把所有已经跟踪过的文件暂存起来一并提交
  • git commit --amend # 修改最后一次提交
  • git reset HEAD # 取消已经暂存的文件
  • git checkout – file # 取消对文件的修改(从暂存区去除file)
  • git checkout branch|tag|commit – file_name # 从仓库取出file覆盖当前分支
  • git checkout – . # 从暂存区去除文件覆盖工作区
  • git branch # 列出本地分支
  • git branch -r # 列出远端分支
  • git branch -a # 列出所有分支
  • git branch -v # 查看各个分支最后一个提交对象的信息
  • git branch --merge # 查看已经合并到当前分支的分支
  • git branch --no-merge # 查看为合并到当前分支的分支
  • git branch test # 新建test分支
  • git checkout test # 切换到test分支
  • git checkout -b test # 新建+切换到test分支
  • git checkout -b test dev # 基于dev新建test分支,并切换
  • git branch -d test # 删除test分支
  • git branch -D test # 强制删除test分支
  • git merge test # 将test分支合并到当前分支
  • git rebase master # 将master分之上超前的提交,变基到当前分支
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值