LoginSignup
8
5

More than 3 years have passed since last update.

Ruby on Railsのアプリケーションをgit cloneする

Posted at

はじめに

学生エンジニアの覚え書きです。参考になれば幸いです。
使用しているPCはMacを使用しているのでWindowsの方は注意してください。

まずはGitHubからcloneをする

クローンするアプリケーションを置きたいディレクトリに移動したあと

$ git clone https://github.com/example/test.git

URLにはクローンしたいリポジトリのURLを入れてください

bundle installをする

クローンしたアプリケーションで使用するgemをインストールします。

$ bundle install

これでうまくいくはずが

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

エラーが出ました
mysql2のgemfileがインストールできない様子

ググって見ると、こちらの記事を発見し解決できました。
【Rails】MySQL2がbundle installできない時の対応方法

$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

このコマンドを打ったあと

$ bundle install

すると、うまくインストールできました。

Bundle complete! 22 Gemfile dependencies, 97 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

データベースの作成

ここからはデータベースを作成していきます。

$ rails db:create
$ rails db:migrate

これでデータベースは作成できました。

アプリケーションの起動

ここまで来たら最後に

$ rails s

をして起動すれば完了です。

最後に

今回はGitHubからcloneしたアプリケーションをローカル環境で動かすことをしました。
起動したあとも正常に動作しない点はあると思うので動作確認は怠らないようにしてください。

注意点としてcloneした際に.gitignoreに指定されているフォルダ、ファイルはcloneされないのでAPIキーなどを.envなどのファイルに書いている方は作成してください。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5