和平简朴的生活,纳言敏行,随遇而安。

Macbook Pro Develop Environment

强迫症患者的MacBook Pro开发环境配置记录

据说强迫症都是有精神洁癖的同志,恰好我又是处女座,所以,你懂得,每隔一段时间我都会把电脑重新安装一次

系统安装篇

每隔一段时间,我会先把自己的资料备份一下,然后Command + r 进入恢复模式,先把磁盘抹掉,然后重新安装macOS。

软件篇

1、首先会把iCloud配置好,同步自己需要的数据,添加好指纹,还有dock的大小调整好。

2、第一个要安装的软件是Cleanapp,这个软件一定要先于其他软件安装,因为他可以监视日志,为以后卸载其他不想要的软件做好准备。

3、Office系列是必须要装的,现在的Office for Mac都是64位的了,在某宝上购买一个正版的Office 365的账号,要不了多少钱,用正版的挺爽,可以一直更新。

4、Adobe系列也是必须要装的,Photoshop,Dreamweaver,Lightroom是我常用的,可以使用Adobe Zii来解决激活问题。

5、iTerm2也是必须安装的,而且装好之后会选择Solarized Dark配色来使用。

6、Sublime这个跨平台的编辑器,现在用起来挺顺手的,推荐一个很舒服的主题:ayu:https://packagecontrol.io/packages/ayu

7、VirtualBox也是一定要安装的,安装一个Debian的虚拟机,然后通过共享文件夹的方式,在Mac上直接编辑文件,把这个文件夹设置为共享文件夹,设置为Nginx的服务目录,通过DNS编辑,把想要设计的网站域名映射到虚拟机上,这样将来发布到远程服务器的时候,所有的配置文件都可以不用修改。

8、Unarchiver用来解压缩也是必须的,不知为何,购买过后的记录不会出现在App Store已购买软件里面。

9、Filezilla,也是一个跨平台的FTP客户端,开源的,支持。

10、ShadowsocksX,这个就不多解释了,科学上网。

11、Chrome,虽然比Safari耗电,但是用来调试web开发,还是很顺手的,另外它的插件SwitchyOmega配合shadowsocks使用,很配。另外livereload插件也很棒。

12、坚果云,Dropbox 被墙之后,国产软件里面这个很良心。

13、QQ,微信,阿里旺旺,有道云笔记等等这些常用的也都挺好的。

开发环境配备

1. 安装 Command Line Tools for Xcode

在终端输入: xcode-select --install 在弹出的对话框选择安装。

2. 安装 Homebrew

在终端输入: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 按照提示安装好 Homebrew

3. 更换默认 shell 为 Fish Shell

网上多数人貌似都推荐用zsh作为默认shell,虽然zsh的扩展很多,但是zsh的缺点是效率不够高,感觉启动慢。 Fish Shell 是一款针对类Unix系统的简洁优美的系统shell,自带的Autosuggestions功能很舒服,还有Glorious VGA Color,配合iterm2使用让人觉得shell很优雅。

step.1 安装 Fish Shell:

三种方法:

可以使用 Homebrew: brew install fish

也可以使用 MacPorts: sudo port install fish

也可以到 Fish Shell 官网下载安装文件来安装:

http://www.fishshell.com/

另外,Fish Shell 还可以作为一个app使用,无需安装,不过这样不方便我们作为shell使用。

step.2 将 Fish Shell作为默认shell使用:

在终端输入: type fish 找到安装过后的fish位置: fish is /usr/local/bin/fish

然后将fish添加到系统默认shell列表中: sudo nano /etc/shells

添加 /usr/local/bin/fish 到文件中:

cat /etc/shells
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/fish

之后使用命令chsh 将默认shell设置为fish

shell> chsh -s /usr/local/bin/fish
Changing shell for standme.
Password: 

之后重新登陆即可

fish-shell> echo $SHELL
/usr/bin/local/fish

这样使用iterm2配合fish就可以有自带Autosuggestions和Glorious VGA Color支持的优雅shell就完成配置了。

4. 升级ruby版本

step.1 首先安装rvm:

curl -L get.rvm.io | bash -s stable

之后将环境变量添加到配置文件里:

source ~/.bashrc
source ~/.bash_profile

使用rvm -v查看rvm版本

step.2 安装ruby最新版本

首先查看ruby版本:ruby -v

列出已知ruby版本:rvm list known

然后安装最新的版本:rvm install ruby-2.3.3

如果新的系统还没有安装homebrew,所以会先安装

=> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
==> The following existing directories will have their owner set to standme:
/usr/local/bin
==> The following existing directories will have their group set to admin:
/usr/local/bin
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin

同时会安装一些依赖的软件包:

installing requirements for osx.
Updating system....
Installing required custom packages: homebrew/dupes homebrew/dupes.
Installing required packages: zlib, autoconf, automake, libtool, pkg-config, coreutils, zlib, libyaml, readline, libksba, openssl............

之后会提示ruby的一些动态库缺失,然后会下载源码重新编译安装:

Libraries missing for ruby-2.3.3: /Users/travis/.rvm/rubies/ruby-2.3.3/lib/libruby.2.3.0.dylib,/usr/local/opt/gdbm/lib/libgdbm.4.dylib. Refer to your system manual for installing libraries
Mounting remote ruby failed with status 10, trying to compile.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/standme/.rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.7M  100 13.7M    0     0  6527k      0  0:00:02  0:00:02 --:--:-- 6528k
ruby-2.3.3 - #extracting ruby-2.3.3 to /Users/standme/.rvm/src/ruby-2.3.3....
ruby-2.3.3 - #configuring...........................................................
ruby-2.3.3 - #post-configuration.
ruby-2.3.3 - #compiling.....\

ruby-2.3.3 安装完成之后,会自动下载必须的gems:
ruby-2.3.3 - #installing.........
ruby-2.3.3 - #making binaries executable..
ruby-2.3.3 - #downloading rubygems-2.6.8
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  736k  100  736k    0     0  2415k      0 --:--:-- --:--:-- --:--:-- 2415k
ruby-2.3.3 - #extracting rubygems-2.6.8....
ruby-2.3.3 - #removing old rubygems.........
ruby-2.3.3 - #installing rubygems-2.6.8...................
ruby-2.3.3 - #gemset created /Users/standme/.rvm/gems/ruby-2.3.3@global
ruby-2.3.3 - #importing gemset /Users/standme/.rvm/gemsets/global.gems...............................................
ruby-2.3.3 - #generating global wrappers........
ruby-2.3.3 - #gemset created /Users/standme/.rvm/gems/ruby-2.3.3
ruby-2.3.3 - #importing gemsetfile /Users/standme/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.3 - #generating default wrappers........
ruby-2.3.3 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.3.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

至此,ruby-2.3.3 升级完成

5.安装middleman

为何要升级Ruby,因为我要安装Middleman,Middleman 依赖Ruby2.2 以上版本才能运行,macOS 自带的Ruby是2.0.0,所以必须升级,Middleman是实用Ruby语言编写的静态网站生成工具,支持Markdown,对于不经常动态更新的个人网站或者是公司站点,很适合。所以打算把个人Blog更换成Middleman生成的静态网站,在MacBook Pro上写文章,更新发布到服务器就可以了。 安装middleman也很简单:

gem install middleman

同样会安装一些依赖的gem包

6. rvm 与 Fish Shell 的整合

两个同样都是非常流行的东西目前整合的时候会因为fish的path出现很多问题,rvm官网给出了当前的解决方案,并且说今后会更好的支持fish:

Since RVM is a large collection of bash scripts and fish is not bash-compatible, users of fish need a wrapper around RVM to make it work properly with that shell. Since RVM just manipulates environment variables, we just need a way to preserve those changes.

解决方法:

step.1 下载rvm官网写好的配置文件:

curl -L --create-dirs -o〜/ .config / fish / functions / rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish

其实内容在这里:

https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish

内容是:

function rvm --description='Ruby enVironment Manager'
  # run RVM and capture the resulting environment
  set --local env_file (mktemp -t rvm.fish.XXXXXXXXXX)
  bash -c 'source ~/.rvm/scripts/rvm; rvm "$@"; status=$?; env > "$0"; exit $status' $env_file $argv

  # apply rvm_* and *PATH variables from the captured environment
  and eval (grep '^rvm\|^[^=]*PATH\|^GEM_HOME' $env_file | grep -v '_clr=' | sed '/^[^=]*PATH/s/:/" "/g; s/^/set -xg /; s/=/ "/; s/$/" ;/; s/(//; s/)//')
  # needed under fish >= 2.2.0
  and set -xg GEM_PATH (echo $GEM_PATH | sed 's/ /:/g')

  # clean up
  rm -f $env_file
end

function __handle_rvmrc_stuff --on-variable PWD
  # Source a .rvmrc file in a directory after changing to it, if it exists.
  # To disable this fature, set rvm_project_rvmrc=0 in $HOME/.rvmrc
  if test "$rvm_project_rvmrc" != 0
    set -l cwd $PWD
    while true
      if contains $cwd "" $HOME "/"
        if test "$rvm_project_rvmrc_default" = 1
          rvm default 1>/dev/null 2>&1
        end
        break
      else
        if test -e .rvmrc -o -e .ruby-version -o -e .ruby-gemset
          eval "rvm reload" > /dev/null
          eval "rvm rvmrc load" >/dev/null
          break
        else
          set cwd (dirname "$cwd")
        end
      end
    end

    set -e cwd
  end
end

之后编辑config.fish文件,激活rvm default:

echo“rvm default”>>〜/ .config/fish/config.fish

其实就是编辑config.fish文件,将rvm default 添加进去即可

之后在fish中使用rvm就可以像在bash或者是zsh里面正常使用一样了