markdown Mac OS X Rails开发环境设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Mac OS X Rails开发环境设置相关的知识,希望对你有一定的参考价值。
# Mac OS X Rails Dev Environment Setup
**Prerequisite:** Be sure to have the latest Xcode installed before proceeding.
## Install Homebrew
Homebrew is the defacto package manager on the OS X platform
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
## Install Mathias’s dotfiles
Sensible hacker defaults for macOS. [More info](https://github.com/mathiasbynens/dotfiles)
git clone https://github.com/mathiasbynens/dotfiles.git && cd dotfiles && source bootstrap.sh
Adds some great features like a bunch of really handy aliases.
Some you can try yourself:
# To list all files including hidden, with forward-slash to denote folders.
la
# To show hidden files in Finder
show
# To hide hidden files in Finder
hide
# To view all the aliases now available for your use
alias
Add the `.extra` as detailed [here](https://github.com/mathiasbynens/dotfiles)
Be sure to check the changes that the `.macos` scipt makes before using it to set some sensible macOS defaults. You may want to comment some out.
## Setup Terminal
- Open **Preferences** for the **Terminal** app.
- Under **Profiles** select **Import** via the settings cog at the bottom of the pane.
- From there, import the _Solarized Dark xterm-256color.terminal_ profile.
- Now select the imported profile in the list and make it the default by clicking the **Default** button at the bottom of the pane.
- Restart the **Terminal** app for the new profile to be enabled.
## Setup the Ruby & Rails Environments
1. Install **rbenv**
[rbenv](https://github.com/rbenv/rbenv) allows for easily installation and switching between various versions of Ruby. More
Install **rbenv**.
brew install rbenv
Set up **rbenv** integration with your shell.
rbenv init
Make **rbenv** load automatically.
if ! grep -i 'eval "$(rbenv init -)"' ~/.bash_profile ; then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile ; fi
Refresh the **Terminal**.
reload
Check that **rbenv** is setup correctly
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
You should get something like this.
![enter image description here](https://image.prntscr.com/image/DdJUSTNJRUGNej4DFzR6bg.png)
2. Install **Ruby**
*Install the version you require*
rbenv install 2.4.1
Set the global Ruby version
rbenv global 2.4.1
Check that it's set
ruby -v
It should return the version you set.
![enter image description here](https://image.prntscr.com/image/6RAtKo7eSpa4asGRe3I7Dg.png)
3. Install **Bundler**
[Bundler](http://bundler.io/) is a [Gem](http://guides.rubygems.org/rubygems-basics/) manager.
gem install bundler
4. Set **Gem** docs generation exclusion.
if ! grep -i 'gem: --no-ri --no-rdoc --no-document' ~/.gemrc ; then echo 'gem: --no-ri --no-rdoc --no-document' >> ~/.gemrc ; fi
5. Install **Rails**
gem install rails
## Setup Postgres
1. Install **Postgres.app**
Download from [here](https://postgresapp.com/) , install, open and select `Initialize`
2. Set the `$PATH`for command line use.
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp && reload
## Create Test Rails App
Here we will create simple blog app
# Create a project directory
mkdir -p ~/Projects/RailsApps
cd ~/Projects/RailsApps
# Create a new app preconfiguring postgres as the database
rails new my_blog -d postgresql
cd my_blog
# Scaffold a Post MVC
rails generate scaffold Post title:string body:text
# Create the db & run migrations
rails db:create db:migrate
#Start the server
rails server
Check that the app is running at http://localhost:3000/
![enter image description here](https://image.prntscr.com/image/F5a5bLJQQOaXPZgfVwJQmA.png)
Check that you can create, edit & delete Posts http://localhost:3000/posts
以上是关于markdown Mac OS X Rails开发环境设置的主要内容,如果未能解决你的问题,请参考以下文章
markdown Ruby on Rails的安装环境(Mac OS X 10.9或更高版本)
markdown Mac OS X上的Docker Machine