Mac重装+初始化配置

Python013

Mac重装+初始化配置,第1张

据我所知的重装Mac系统的方法有三种:

具体的操作方式可以在网上查,本人懒一点,再加上网速还可以,就用了最省事的在线重装。

首先我就安装了Xcode,吃饭的家伙,必须要先保证有。然后安装了搜狗输入法、Clean My Mac、 有道词典、腾讯QQ、 为知笔记、 网易云音乐、 Dash、 Source Tree、 iStat Menus、 Snip、 The Unarchiver、 XMind这几个软件,其他的以后想起来再安装。

指定位置

然后通过命令

查到我的RVM版本是1.27.0。

查到我的ruby版本是2.0.0p648。

然后通过命令

查到最新的版本是2.3.0。

通过命令

来安装在最新版本的ruby,但是它提示你没有安装Homebrew,输入路径进行安装,按回车键选择默认位置,然后一路回车,安装brew完毕,然后终端自动继续安装ruby 2.3.0,安装成功。

查到系统默认的gem的源是 https://rubygems.org/ ,这个在国内有被墙的危险, 所以要改为国内的淘宝源。 因为近期淘宝的ruby镜像网站已经放弃维护,RubyGems 镜像的管理工作以后将交由 [Ruby China](https://gems.ruby-china.com/) 负责,所以之前的淘宝镜像已经不能使用了。同时,Ruby China的镜像网址也由https://gems.ruby-china.org/替换为https://gems.ruby-china.com/,请大家注意及时更改!

然后对gem进行更新

更新后的版本为2.6.6。

来使隐藏文件失效,必须重启finer才能生效。

安装Cocoapods。

在很短的时间内就安装好了。

在文件中粘贴

command script import /usr/local/opt/chisel/libexec/fblldb.py

这段话,并进行保存。

在更新到10.12的系统后,发现在系统偏好设置->安全性和隐私->通用里面去掉了“任何来源“选项,导致没有签名的应用没办法安装,只允许AppStore和被认可的开发者的应用可以安装。

在终端输入

命令,就可以重新看到”任何来源“了。

就先配置到这里,差不多可以用了,有啥添加的再看具体情况就可以了。

安装Xcode 4.1,Xcode4.2以及更高的版本在 Lion 仍然存在一些兼容性问题,强烈建议使用XCode 4.1,下载地址:

安装RVM

$ bash <<(curl -s )

配置RVM自动加载,将下面这一行代码添加到~/.bash_profile中,然后退出iTerm并重新启动

[[ -s $HOME/.rvm/scripts/rvm ]] &&source $HOME/.rvm/scripts/rvm

安装 ruby-1.9.2-p290

$ rvm install 1.9.2

设置系统默认使用 ruby-1.9.2

$ rvm use 1.9.2 --default

步骤1 安装 Rails

安装Rails

$ gem install rails

Rails安装完成后,创建一个rails项目,假定你的项目叫做:awesome project

$ rails new awesome_project

启动Rails,并访问

$ cd awesome_project $ rails server

步骤2 安装 Passenger 和 Nginx

首先通过gem安装passenger

$ gem install passenger

因为Nginx不支持动态module载入,所以需要通过Passenger来自动下载,编译,安装由Passenger修改版的Nginx:

安装Passenger + Nginx

$ passenger-install-nginx-module

Yes: download, compile and install Nginx for me. (recommended) The easiest way to get started. A stock Nginx 1.0.10 with Passenger support, but with no other additional third party modules, will be installed for you to a directory of your choice.

No: I want to customize my Nginx installation. (for advanced users) Choose this if you want to compile Nginx with more third party modules besides Passenger, or if you need to pass additional options to Nginx's 'configure' script. This installer will 1) ask you for the location of the Nginx source code, 2) run the 'configure' script according to your instructions, and 3) run 'make install'.

Whichever you choose, if you already have an existing Nginx configuration file, then it will be preserved.

Enter your choice (1 or 2) or press Ctrl-C to abort: 这里建议选择1

Please specify a prefix directory [/opt/nginx]: /usr/local/nginx

当询问nginx的安装路径的时候,个人建议安装到/usr/local/nginx下

当安装完成后,会在console中提示如何配置Nginx

Passenger会自动帮你将下面两行添加到Nginx的配置文件中/usr/local/nginx/conf/nginx.conf(很人性化)

http { ... passenger_root /Users/Daniel/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.10passenger_ruby /Users/Daniel/.rvm/wrappers/ruby-1.9.2-p290/ruby... }

server { listen 80server_name www.yourhost.comroot /somewhere/public# <--- be sure to point to 'public'! passenger_enabled on}

请不要忘记将nginx命令行程序连接到/usr/local/sbin

$ sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

步骤3 配置Nginx + Passenger + Rails

修改hosts文件,给你的项目一个本地域名, 比如awesome_project.local

$ sudo vim /etc/hosts

127.0.0.1 awesome_project.local

测试hosts

$ ping awesome_project.local

PING awesome_project.local (127.0.0.1): 56 data bytes

64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.054 ms

继续配置Nginx, 这里我给出一个最小可运行的Nginx配置文件

$ vim /usr/local/nginx/conf/nginx.conf

nginx.conf

worker_processes 1

events {

worker_connections 1024

}

http {

passenger_root /Users/Daniel/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.10

passenger_ruby /Users/Daniel/.rvm/wrappers/ruby-1.9.2-p290/ruby

include mime.types

default_type application/octet-stream

sendfile on

keepalive_timeout 65

server {

listen 80

server_name awesome_project.local

root /Users/Daniel/awesome_project/public

passenger_enabled on

rails_env development

}

}

测试Nginx的配置文件语法是否正确

$ sudo nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动Nginx

$ sudo nginx

如何在修改Nginx的配置文件后,让Nginx载入新配置

$ sudo nginx -s reload

如何停止Nginx

$ sudo nginx -s stop

如何在不停Nginx的情况下,重新启动Passenger

$ cd path/to/your/awesome/project

$ touch tmp/restart.txt

好了,这个时候你可以打开浏览器,访问你的awesome_project网站了