gem rvm bundle

rvm 是用来管理 ruby 的,ruby 的其中一个“程序”叫 rubygems ,简称 gem,而用来管理项目的 gem 的,叫 bundle ,他俩完全是不同的东西,相同的只是都可以管理gem。



$gem sources -l
** CURRENT SOURCES **



https://rubygems.org/



添加 TUNA 源并移除默认源


gem sources –add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ –remove https://rubygems.org/


列出已有源


gem sources -l


应该只有 TUNA 一个



$gem sources –add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ –remove https://rubygems.org/
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
https://mirrors.tuna.tsinghua.edu.cn/rubygems/ added to sources
https://rubygems.org/ removed from sources




$sudo gem install maruku
Password:
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
Fetching: maruku-0.7.3.gem (100%)
ERROR: While executing gem … (Errno::EPERM)
Operation not permitted - /usr/bin/maruku



$gem environment
RubyGems Environment:



  • RUBYGEMS VERSION: 2.6.13

  • RUBY VERSION: 2.0.0 (2015-04-13 patchlevel 645) [universal.x86_64-darwin15]

  • INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0

  • USER INSTALLATION DIRECTORY: /Users/didi/.gem/ruby/2.0.0

  • RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby

  • EXECUTABLE DIRECTORY: /usr/bin



运行一下命令,执行成功
sudo gem install -n /usr/local/bin maruku
gem 可以指定安装位置



bundle install 安装当前项目的 gem 库
安装:
gem install bundler
创建 gemfile 文件
cd 项目目录
bundle init



在 Gemfile 里添加如下代码,指定 pod 版本



frozen_string_literal: true


source “https://rubygems.org”



gem “rails”


gem ‘cocoapods’, ‘0.39.0’



在之前执行的命令前面加上 bundle exec 就好了,如:



bundle exec pod install –verbose –no-repo-update
或者



bundle exec pod update –verbose –no-repo-update



更改source


source ‘https://rubygems.org’


source ‘https://gems.ruby-china.com’



$bundle install
bundle: cannot find package in current directory: no buildable Go source files in /Users/didi/blog/MyBlog



首先,Gemfile 文件所列的 gem 只是项目依赖的一部分,gem 本身也有自己的依赖,不同的 gem 本身可能依赖了某一 gem 不同的版本,如何让这么多不同版本的依赖相安无事,不发生冲突,这就是 bundle 的发挥作用的时候了。bundle 不仅用来安装 gem,更重要的是还负责计算出不同 gem 的依赖版本,最终生成 Gemfile.lock 文件,该文件记录了确切的 gem 名称和版本号,以及他们所依赖的 gem 的名称和版本号。



第一次运行 bundle install 时自动生成 Gemfile.lock 文件。
以后每次运行 bundle install 时,如果 Gemfile 中的条目不变 bundle 就不会再次计算 gem 依赖版本号,直接根据 Gemfile.lock 检查和安装 gem。
如果出现依赖冲突时可以通过 bundle update 更新 Gemfile.lock。



http://jekyllcn.com/
https://blog.csdn.net/efvn2008/article/details/48392047



https://ruby-china.org/wiki/rvm-guide



RVM 是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换。



https://rvm.io/



安装最新版本的Ruby的RVM










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


列出可供RVM使用的Ruby版本rvm list



rvm use 2.4.1



https://www.jianshu.com/p/c44ef74d99f9



的’requirements_osx_brew_update_system’错误



“Error running ‘requirements_osx_brew_update_system ruby-2.2.2’, showing last 15 lines of /Users/jolie/.rvm/log/1471244386_ruby-2.2.2/update_system.log https://github.com/Homebrew/homebrew/wiki/Common-Issues



根据提示猜测是homebrew的版本过低的原因, 就去更新一下, 发现由于是新系统所以brew update或者brew upgrade都不好使, 于是就去查找解决办法, 发现卸载重装就好用, 如果正好搜到我的简书就省的走弯路了, 因为以前安装过brew的电脑就不能使用brew的安装命令了



// 安装命令
ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”



// 以前安装过使用这个命令
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
// 如果还是更新不了就先执行这个命令卸载brew
ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”



$ gem sources -r https://ruby.taobao.org // 我移除了淘宝源, 现在淘宝源是https的
$ gem sources -a http://rubygems-china.oss.aliyuncs.com //添加china的源



$ rvm get master
Downloading https://get.rvm.io
No GPG software exists to validate rvm-installer, skipping.
Downloading https://github.com/rvm/rvm/archive/master.tar.gz



$ rvm install 2.4.1
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/x86_64/ruby-2.4.1.



解决办法:
1、Install Xcode and the Command Line Tools
2、brew install autoconf automake libtool
pkg-config apple-gcc42 libyaml readline libxml2 libxslt
libksba openssl sqlite



$sudo xcode-select –install
Password:
xcode-select: error: command line tools are already installed, use “Software Update” to install updates



先运行下面命令,再安装:
rvm autolibs read-only



$ rvm install 2.4.1



ruby-2.4.1 - #extracting rubygems-3.0.8…..
ruby-2.4.1 - #removing old rubygems……..
ruby-2.4.1 - #installing rubygems-3.0.8..
Error running ‘env GEM_HOME=/Users/didi/.rvm/gems/ruby-2.4.1@global GEM_PATH= /Users/didi/.rvm/rubies/ruby-2.4.1/bin/ruby -d /Users/didi/.rvm/src/rubygems-3.0.8/setup.rb –no-document’,
please read /Users/didi/.rvm/log/1590048839_ruby-2.4.1/rubygems.install.log



$rvm use 2.4.1
Using /Users/didi/.rvm/gems/ruby-2.4.1



$ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]



$jekyll serve
Configuration file: /Users/didi/blog/MyBlog/_config.yml
Source: /Users/didi/blog/MyBlog
Destination: /Users/didi/blog/MyBlog/_site
Generating…
Liquid Exception: Traceback (most recent call last): File “/Library/Ruby/Gems/2.0.0/gems/pygments.rb-0.5.4/lib/pygments/mentos.py”, line 303



$bundler
The latest bundler is 1.16.1, but you are currently running 1.15.4.
Gem::InstallError: public_suffix requires Ruby version



= 2.1.
An error occurred while installing
public_suffix (3.0.2), and Bundler cannot continue.
Make sure that gem install public_suffix -v '3.0.2'
succeeds before bundling.




$rvm use 2.4.1
$bundler
/Library/Ruby/Site/2.0.0/rubygems.rb:271:in `find_spec_for_exe’: can’t find gem bundler (>= 0.a) (Gem::GemNotFoundException)



  gem uninstall bundler



  gem install bundler –version ‘1.17.2’



$rvm list
=> ruby-2.4.1 [ x86_64 ]



Default ruby not set. Try ‘rvm alias create default ’.



=> - current


=* - current && default


* - default



$rvm use ruby-2.4.1 –default
Using /Users/didi/.rvm/gems/ruby-2.4.1



$ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]



$which ruby
/Users/didi/.rvm/rubies/ruby-2.4.1/bin/ruby



vi .bashrc
alias ruby=”/Users/didi/.rvm/rubies/ruby-2.4.1/bin/ruby”
source .bashrc



$sudo gem install public_suffix -v ‘3.0.2’
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store



$which ruby
/usr/bin/ruby
$ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
$/usr/bin/ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]



$vi ~/.bashrc
PATH=”/Users/didi/.rvm/rubies/ruby-2.4.1/bin:$PATH”



$ which ruby
/Users/didi/.rvm/rubies/ruby-2.4.1/bin/ruby



$which gem
/usr/bin/gem



$gem -v
2.6.13



$sudo gem update –system
Password:
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)



RubyGems 2.6.13 installed
Parsing documentation for rubygems-2.6.13



$gem install public_suffix -v ‘3.0.2’



$gem -v
3.0.8



$sudo gem install public_suffix -v ‘3.0.2’
ERROR: Loading command: install (LoadError)
cannot load such file – openssl
ERROR: While executing gem … (NoMethodError)
undefined method `invoke_with_build_args’ for nil:NilClass



解决方式:
1、cd ruby/ruby-2.5.1/ext/zlib目录



ruby ./extconf.rb
make
make install



2、make时报错:make: *** No rule to make target /include/ruby.h’, needed byzlib.o’. Stop.



3、更改Makefile文件,
zlib.o: $(top_srcdir)/include/ruby.h 改成
zlib.o: ../../include/ruby.h;然后重新make就可以了。



4、cd ruby/ruby-2.5.1/ext/openssl目录执行 ruby ./extconf.rb、make 、make install命令。



Gem::InstallError: public_suffix requires Ruby version >= 2.1.
An error occurred while installing public_suffix (3.0.2), and
Bundler cannot continue.
Make sure that gem install public_suffix -v '3.0.2' succeeds before
bundling.



$rvm pkg install openssl



Beware, ‘rvm pkg …’ is deprecate



系统中是有 openssl 的,而且 openssl 可以正常工作,只是 ruby 找不到它。至于为什么突然找不到了,那就不太清楚了,推测可能是更新 OS X 时引发的问题吧。试了很多方法,各种不奏效,最后通过以下的方法解决了。大体思路是用 rvm 重新安装 openssl,然后重新安装 ruby,并指定 openssl 的路径。 



    1.rvm pkg install openssl



    2.rvm reinstall ruby-2.2 –with-openssl-dir=$rvm_path/usr



$jekyll s
/Library/Ruby/Site/2.0.0/rubygems.rb:271:in `find_spec_for_exe’: can’t find gem jekyll (>= 0.a) (Gem::GemNotFoundException)



$ sudo gem install -n /usr/local/bin cocoapods
$gem install jekyll



$jekyll serve


Category web