mac rails环境搭建 下载的软件整理

需要下载的软件及对应链接


xcode

可在app store直接安装


rubymine

破解1

破解2


sourcetree

安装步骤


iterm

------------------------------------------------------------------

下面3款软件是工作中会用到的,可选择性下载


有道云


xmind zen

xmind

未破解


axure

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

rails 环境搭建

Xcode

是运行在操作系统Mac OS X上的集成开发工具(IDE),由Apple Inc开发。Xcode是开发 macOS 和 iOS 应用程序的最快捷的方式。Xcode 具有统一的用户界面设计,编码、测试、调试都在一个简单的窗口内完成

HomeBrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。

RVM

rvm是一个便捷的多版本ruby环境的管理和切换工具


1

安装Xcode 在 apple store中可以下载安装,或者Command Line Tools For Xcode,这个可直接在终端输入命令下载

xcode-select --install

注意:appstore 上若没有,可能由于系统版本问题,需升级


2

安装Homebrew 可在终端(iterm)直接输入

/user/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor  #目的是为了检测是否有什么地方冲突

想要移除Homebrew

/user/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

3

安装rvm

注意:例如如果安装ruby的版本为2.2.2,那么rvm的版本必须高于2.2.2

curl -sSL https://get.rvm.io | bash -s stable --ruby

在安装过程中出现permission denied
解决方法:修改安装目录的权限

chmod + R 777 chmod -R 777 /Users/xxxusername/

载入rvm环境

source ~/.rvm/scripts/rvm   

4

用RVM安装ruby环境

rvm list known               #列出已知的ruby版本
rvm install 2.0.0            #选择现有的rvm版本来进行安装  默认使用了安装好的,没有安装
rvm list                      #查询已经安装的ruby
rvm remove 1.9.2              #卸载一个已安装版本 

RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本

 rvm 2.1.4 --default

ruby安装流程

国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成淘宝的,替换方式如下:

$ gem source -r https://rubygems.org/       #remove


$ gem source -a https://ruby.taobao.org   
或者 $ gem source -a https://ruby-china.com 

要想验证是否替换成功了,可以执行:

$ gem sources -l

正常的输出结果:

            CURRENT SOURCES            

      http://ruby.taobao.org/

到这里就已经把Ruby环境成功的安装到了Mac OS X上,接下来就可以进行相应的开发使用了。


5

安装bundle

gem install bundler

安装所遇到的错误解决

#报错

ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Library/Ruby/Gems/2.3.0/gems/bundler-2.0.1/CHANGELOG.md
#解决方法

gem install -n /usr/local/bin bundle

安装过程中报错

#报错

Gem files will remain installed in /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17 for inspection.
Results logged to /Users/zhangyarong/.rvm/gems/ruby-2.2.2/extensions/x86_64-darwin-18/2.2.0/libv8-3.16.14.17/gem_make.out

An error occurred while installing libv8 (3.16.14.17), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.17' --source 'https://gems.ruby-china.com/'` succeeds before bundling.

In Gemfile:
  therubyracer was resolved to 0.12.3, which depends on
    libv8

解决方法

#换成自己需要的版本
gem uninstall libv8
gem install therubyracer -v '0.11.3'
gem install libv8 -v '3.11.8.13' -- --with-system-v8

6

安装rails

gem install rails
报错
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.
解决方法
sudo gem install -n /usr/local/bin rails

安装mysql

brew install mysql

从码云上拉去代码,需要先配置git

1

ssh-keygen -t rsa -C "邮箱"

#运行后展示
Generating public/private rsa key pair.
Enter file in which to save the key (xxxxxx):
Created directory '/Users/zhangyarong/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in  xxxx.
Your public key has been saved in xxxx.
The key fingerprint is:
SHA256:
The key's randomart image is:
+---[RSA 2048]----+
| . o.            |
|  =.             |
| ooo. .          |
|.o*+ . .         |
| +=+. + S        |
|  Bo.o * o       |
| X *+o= B        |
|+ =.+o+=.*       |
| ....  +E .      |
+----[SHA256]-----+

2

#查询公钥

admin:~ root$ vi /xxx/xxx/.ssh/id_rsa.pub

3

从git上复制ssh ,然后在sourcetree中 新建 从URl克隆 即可拉下代码


需在config文件下增加一个数据库文件database.yml文件


7

在rubymine中 启动时出错

rails s

1)

mysql2版本问题
解决方法
bundle update --source mysql2

2)

therubyracer版本问题
bundle update therubyracer

可能会再次遇到mysql版本问题
就在次运行1的代码


8

执行bundle install时报错

Building native extensions. This could take a while...
ERROR:  Error installing libv8:
        ERROR: Failed to build gem native extension.

    current directory: /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/ext/libv8
/Users/zhangyarong/.rvm/rubies/ruby-2.2.2/bin/ruby -I /Users/zhangyarong/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0 -r ./siteconf20190530-75806-cy8diz.rb extconf.rb
creating Makefile
Applying /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/patches/fPIC-for-static.patch
Applying /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/patches/do-not-imply-vfp3-and-armv7.patch
Applying /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/patches/disable-building-tests.patch
Applying /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/patches/disable-werror-on-osx.patch
Applying /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/patches/do-not-use-vfp2.patch
Compiling v8 for x64
Using python 2.7.10
Using compiler: c++ (Apple LLVM version 10.0.1)
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
Building v8 with env CXX=c++ LINK=c++  /usr/bin/make x64.release ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
        build/gyp/gyp --generator-output="out" build/all.gyp \
                      -Ibuild/standalone.gypi --depth=. \
                      -Dv8_target_arch=x64 \
                      -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
  CXX(target) /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from ../src/allocation.cc:33:
../src/utils.h:33:10: fatal error: 'climits' file not found
#include <climits>
         ^~~~~~~~~
1 warning and 1 error generated.
make[1]: *** [/Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o] Error 1
make: *** [x64.release] Error 2
/Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive '/Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
        from /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/ext/libv8/location.rb:35:in `each'
        from /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/ext/libv8/location.rb:35:in `verify_installation!'
        from /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17/ext/libv8/location.rb:26:in `install!'
        from extconf.rb:7:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/zhangyarong/.rvm/gems/ruby-2.2.2/gems/libv8-3.16.14.17 for inspection.
Results logged to /Users/zhangyarong/.rvm/gems/ruby-2.2.2/extensions/x86_64-darwin-18/2.2.0/libv8-3.16.14.17/gem_make.out

# 解决方法

gem install libv8 -v '3.11.8.17' -- --with-system-v8

gcc 安装

修改mac默认的gcc到自己安装的gcc


9

  1. 创建文件database.yml
  2. 修改database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: YBH-mall_development

test:
  <<: *default
  database: YBH-mall_test
  
production:
  <<: *default
  database: YBH-mall_development
  username: root
  password: 
  
  1. rake db:create
  2. rails db:migrate
  3. mysql.server start / mysql.server stop
  4. rails s
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值