rbenvとruby-buildでRubyのインストール環境を揃える
- gitをインストール
1 |
yum install -y git |
- gitをインストールしたら次にrbenvをインストール
1 |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv |
1 |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile |
1 |
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile |
1 |
source ~/.bash_profile |
ruby-buildをインストール
1 |
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build |
1 |
cd ~/.rbenv/plugins/ruby-build |
1 |
./install.sh |
Ruby 2.3.1をインストール
1 2 3 4 5 6 7 8 |
rbenv install -l 実行結果 2.3.1 2.4.0-dev . . . |
- はじめにrubyの依存パッケージをインストール
1 |
yum install -y bzip2 make gcc openssl-devel readline-devel zlib-devel |
- rubyをインストール
1 |
rbenv install 2.3.1 |
- gemでインストールした実行ファイルを実行するようにする
1 |
rbenv rehash |
globalでrubyの実行versionを指定
1 |
rbenv global 2.3.1 |
- 最後に確認
1 2 3 4 |
ruby -v 実行結果 ruby 2.3.1p112 (2016-04-26 revision 54768) |
※ whichが無い場合は
1 |
yum install -y which |
1 2 3 4 |
which ruby 実行結果 ~/.rbenv/shims/ruby |
1 2 3 4 |
which gem 実行結果 ~/.rbenv/shims/gem |
Vagrantで共有フォルダのマウントが失敗するときの対処方法(ffiをインストールして解決)
現象
vagrant upで仮想マシンを起動する際、以下のようなメッセージが出て、共有フォルダのマウントに失敗することがある。
1 |
$ vagrant up |
1 2 3 4 5 6 7 8 9 10 11 |
Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant The error output from the last command was: /sbin/mount.vboxsf: mounting failed with the error: No such device |
原因
ホスト⇔ゲスト間のフォルダ共有機能はGuest Additionsが提供しているが
ホスト(VirtualBox)とゲスト(Guest Additions)でバージョン不一致があるとマウントエラーが発生するようだ。
実行環境
Vagrant: 1.8.1
VirtualBox: 5.0.16
GuestAdditions: 4.1.6
対策
vagrant up時に自動的に新しいバージョンのGuest Additionsに更新してくれる「vagrant-vbguest」というプラグインがあるので、インストールしておくと良い。
インストール手順
1 |
$ vagrant plugin install vagrant-vbguest |
しかし、’ffi’がインストール出来ないとのエラーが出た。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Installing the 'vagrant-vbguest' plugin. This can take a few minutes... Bundler, the underlying system Vagrant uses to install plugins, reported an error. The error is shown below. These errors are usually caused by misconfigured plugin installations or transient network issues. The error from Bundler is: An error occurred while installing ffi (1.9.14), and Bundler cannot continue. Make sure that `gem install ffi -v '1.9.14'` succeeds before bundling. Warning: this Gemfile contains multiple primary sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. To upgrade this warning to an error, run `bundle config disable_multisource true`.Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /opt/vagrant/embedded/bin/ruby -r ./siteconf20160922-2725-1e3o1nc.rb extconf.rb checking for ffi.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/opt/vagrant/embedded/bin/$(RUBY_BASE_NAME) --with-ffi_c-dir --without-ffi_c-dir --with-ffi_c-include --without-ffi_c-include=${ffi_c-dir}/include --with-ffi_c-lib --without-ffi_c-lib=${ffi_c-dir}/lib --with-libffi-config --without-libffi-config --with-pkg-config --without-pkg-config /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:524:in `with_werror' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:321:in `open' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:321:in `open' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:347:in `postpone' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for' from /opt/vagrant/embedded/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header' from extconf.rb:16:in `<main>' extconf failed, exit code 1 |
以下のコマンドで’ffi’をインストールする。
1 |
$ gem install --install-dir ~/.vagrant.d/gems 'ffi' -v '1.9.14' |
再度インストールを試みる。
1 |
$ vagrant plugin install vagrant-vbguest |
1 |
Installed the plugin 'vagrant-vbguest (0.13.0)'! |
vbguestのステータスを確認する。
1 |
$ vagrant vbguest --status |
1 |
[default] GuestAdditions versions on your host (5.0.16) and guest (4.1.6) do not match. |
ゲストの方がホストより古いため、ゲスト側をアップデートする。
1 |
$ vagrant vbguest |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[default] GuestAdditions versions on your host (5.0.16) and guest (4.1.6) do not match. --中略-- Complete! Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso Installing Virtualbox Guest Additions 5.0.16 - guest version is 4.1.6 Verifying archive integrity... All good. Uncompressing VirtualBox 5.0.16 Guest Additions for Linux............ VirtualBox Guest Additions installer Removing installed version 4.1.6 of VirtualBox Guest Additions... Copying additional installer modules ... Installing additional modules ... Removing existing VirtualBox non-DKMS kernel modules[ OK ] Building the VirtualBox Guest Additions kernel modules Building the main Guest Additions module[ OK ] Building the shared folder support module[ OK ] Building the OpenGL support module[FAILED] (Look at /var/log/vboxadd-install.log to find out what went wrong. The module is not built but the others are.) Doing non-kernel setup of the Guest Additions[ OK ] Starting the VirtualBox Guest Additions [ OK ] Installing the Window System drivers Could not find the X.Org or XFree86 Window System, skipping. An error occurred during installation of VirtualBox Guest Additions 5.0.16. Some functionality may not work as intended. In most cases it is OK that the "Window System drivers" installation failed. |
Building the shared folder support module[ OK ] と出ていればOK。
(Building the OpenGL support moduleのエラーは無視してOK)
最後に、仮想マシンを再起動する。
1 |
$ vagrant reload |
仮想マシンの起動時に、共有フォルダのマウント失敗が解消された。
1 2 |
--中略-- [default] GuestAdditions 5.0.16 running --- OK. |
Serverspecでnginxのバージョンをテストする
nginx -vでの出力はstderrを指定すれば、テストが通るというメモを記す。
nginx -vで、nginxのバージョンを確認する。
1 2 |
出力結果: nginx version: nginx/1.4.6 (Ubuntu) |
“stdout”では失敗する。
1 2 3 4 5 6 |
// nginx_spec.rb # Check installed package version describe command("nginx -v") do its(:exit_status) { should eq 0 } its(:stdout) { should match /1.4.6/ } end |
1 2 3 4 5 |
テスト結果: 1) Command "nginx -v" stdout should match /1.4.6/ On host `melody` Failure/Error: its(:stdout) { should match /1.4.6/ } expected "" to match /1.4.6/ |
“stderr”にすると成功する。
1 2 3 4 5 6 |
// nginx_spec.rb # Check installed package version describe command(`nginx -v`) do its(:exit_status) { should eq 0 } its(:stderr) { should match /1.4.6/ } end |
1 2 3 4 5 6 7 8 |
テスト結果: Command "nginx -v" exit_status should eq 0 stderr should match /1.4.6/ Finished in * seconds (files took * seconds to load) 2 examples, 0 failures |
どうやらnginxの仕様らしい。
Why write nginx version on stderr?
gccやjavaも同じ類のようである。
Xcodeを使う上で最初におさえること
XcodeとSwiftを使い始めたので、最初におさえるポイントをメモする。
Xcodeの説明
詳しくは以下のリンクに丁寧に紹介されている。
参考:http://www.atmarkit.co.jp/ait/articles/1601/08/news059_2.html
一つのiPhoneアプリを仕上げるために
- Swiftの知識はもちろん必要
- Xcodeに備わっているいくつかの機能を使う
ざっくり言うと、
Storyboardで、アプリのビューを作り、
Swiftで、コードを書いて、アプリを仕上げる。
「Xcodeプロジェクト」とは?
1つのiPhoneアプリを構築する上で必要なプログラムやアセット(画像、動画、音声など)などのファイルを一まとまりにしたもの
iPhoneアプリ作成で利用する「iOS SDK」
⇨ iPhoneアプリを作る上で必要なクラスなどのプログラムやアセットファイルがAppleから提供されている
iOS SDKの中には、さまざまなクラスが用途別に分かれて入っている。
⇨ 例えば、UIKit = 画面上に表示するボタンやスイッチなどパーツ
などである。
Xcodeプロジェクトの作り方
iPhoneアプリで使えるテンプレートには、次の5つ
テンプレート名 | 説明 | テンプレートが合うiPhoneアプリ |
---|---|---|
Master-Detail Application | リスト画面と詳細画面がセットで用意される | ニュースアプリなど、たくさんのコンテンツがあるアプリで使える |
Page-Based Application | 横スワイプで表示が切り替えられる画面が用意される | 本のような使い方の読み物アプリで使える |
Single View Application | 真っ白な画面だけが用意される | シンプルなので、あらゆるアプリで使える ←最もシンプル |
Tabbed Application | 画面下部にタブが表示されている画面が用意される | いくつかの機能を持ち合わせる、多機能なアプリによく使われる |
Game | ゲームを作るための構成が用意される | ゲームアプリで使える |
Xcodeワークスペースの各機能の役割
http://image.itmedia.co.jp/l/im/ait/articles/1601/08/l_swift8_workspace-01.jpg
- 1.ツールバー
- 2.ナビゲーター領域
- 3.エディタ領域
- 4.ユーティリティー領域
- 5.デバッグ領域
Xcodeプロジェクトの構成
http://image.itmedia.co.jp/ait/articles/1601/08/swift8_prj-structure-01.jpg
ファイル名 | 役割・用途 |
---|---|
AppDelegate.swift | アプリのさまざまなイベント(起動、終了、プッシュ通知など)を受け取るためのクラスが書かれたファイル |
ViewController.swift | 初めに表示される画面に何を表示するか制御を行うクラスが書かれたファイル |
Main.storyboard | 「画面にどのようなUI(部品)を置くか」や、画面と画面の切り替えを決めるファイル |
Assets.xcassets | アプリに組み込むアセットファイル(画像など)を管理するファイル |
LaunchScreen.storyboard | アプリが起動してすぐに表示される画面のレイアウトを決めるファイル |
Info.plist | アプリの詳細な設定を定義するファイル |