hachiNote

勉強したことをメモします。

GitをCentOS5にインストールする

目的

さて、Railsがインストールできたので、ここからはWeb+DB Press vol.58の特集記事「詳細Rails 3」にしたがってしばらく作業を進めます。

記事いわく、

Rails 3は全面的にGitを採用しているので、まだSubversionなどを使っている人は、よほどの事情がない限りGitに乗り換えることを推奨します

だそうです。ふむふむ。じゃあ早速Gitを入れてみましょう。

ここでの作業環境は、CentOS 5.3です。

Gitのサイトからソースを取ってきてインストール?

Gitの公式サイトはこちら。
http://git-scm.com/

ついでにウィキペディアでGitについて学ぶ。あのLinuxの作者リーナスさんが作ったツールなんですね。Linuxのコード管理をこれでやってきたということらしいです。

GitのサイトからRPMをダウンロードしてきて入れようと思いましたが、なんかRPMのファイルもいろいろあってよくわかりません。

なので、いろんなサイトで紹介されているソースをビルドする方法を試みます。この間覚えたcheckinstallを使って、ソースからRPMを作ってインストールしようという作戦です。

# wget http://www.kernel.org/pub/software/scm/git/git-1.7.3.4.tar.gz
# tar xzvf git-1.7.3.4.tar.gz
# cd git-1.7.3.4
# ./configure
# /usr/local/sbin/checkinstall

**********************************************************************

 Done. The new package has been saved to

 /usr/src/redhat/RPMS/i386/git-1.7.3.4-1.i386.rpm
 You can install it in your system anytime using:

      rpm -i git-1.7.3.4-1.i386.rpm

**********************************************************************

# rpm -ivh /usr/src/redhat/RPMS/i386/git-1.7.3.4-1.i386.rpm
エラー: 依存性の欠如:
        perl(SVN::Core) は git-1.7.3.4-1.i386 に必要とされています

結果、エラーです。perl(SVN::Core)が必要と言われてますが、これがまたよくわからなくて、CPANで拾ってきて入れるとかいうものじゃないみたいなんですよね。

ネットで調べてみても、Subversionを入れれば一緒についてくるなんて話もありますが、それじゃああんまりだし……としばし作業停止。

rpmforgeのリポジトリからyum経由でGitをインストールする

見方を変えてネットで調べてみたところ、rpmforgeというリポジトリからGitをインストールできるという記事を発見。

断片的な情報から判断すると、rpmforgeとはLinuxyumで標準で探しに行くリポジトリにないような、いろんなRPMを集めたリポジトリみたいですね。これをyumの対象リポジトリに追加すると、今までよりももっと多くのアプリケーションをyumで手軽にインストールできると。

rpmforgeをyumリポジトリとして追加してみる。 /etc/yum.repo.d/rpmforge.repo を作成し、以下のように書く。

[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
enabled = 0
gpgcheck = 0

これでいいのかな? とりあえずやってみよう。

# yum --enablerepo=rpmforge install git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * rpmforge: apt.sw.be
 * base: rsync.atworks.co.jp
 * updates: rsync.atworks.co.jp
 * addons: rsync.atworks.co.jp
 * extras: rsync.atworks.co.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
There are unfinished transactions remaining. You mightconsider running yum-complete-transaction first to finish them.
--> Running transaction check
---> Package git.i386 0:1.7.3-1.el5.rf set to be updated
--> Processing Dependency: perl-Git = 1.7.3-1.el5.rf for package: git
--> Processing Dependency: perl(Git) for package: git
--> Running transaction check
---> Package perl-Git.i386 0:1.7.3-1.el5.rf set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
 Package                                Arch                               Version                                        Repository                              Size
=========================================================================================
Installing:
 git                                    i386                               1.7.3-1.el5.rf                                 rpmforge                               6.1 M
Installing for dependencies:
 perl-Git                               i386                               1.7.3-1.el5.rf                                 rpmforge                                24 k

Transaction Summary
=========================================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 6.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): perl-Git-1.7.3-1.el5.rf.i386.rpm                                |  24 kB     00:00
(2/2): git-1.7.3-1.el5.rf.i386.rpm                                     | 6.1 MB     00:09
-----------------------------------------------------------------------------------------
Total                                                         515 kB/s | 6.1 MB     00:12
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : git                                               [1/2]
  Installing     : perl-Git                                          [2/2]

Installed: git.i386 0:1.7.3-1.el5.rf
Dependency Installed: perl-Git.i386 0:1.7.3-1.el5.rf
Complete!

# git --version
git version 1.7.3

やった! できたできた。おお、rpmforge便利。

いろんなサイトの情報を見ていると、rpmforgeを利用するにはrpmforge-releaseっていうののインストールと、GPGキーのインストールを行わないといけないみたいだけど、そのへん何もやらなくても上記の/etc/yum.repo.d/rpmforge.repoを作成でするだけでできてしまった。なんでだろ。

……む、よく見ると、GPGキーをインストールする手順を紹介している場合は、gpgcheck=1 とファイルに書いてありますね。なるほど。0だとキーのチェックをしない?ということなのか。

rpmforge-releaseは何のためにインストールするんだろ……。うーん、わからないけど、とりあえずインストールできたからいいや。

あと、インストールのログを良く見てみると、gitとともにperl-Gitというパッケージも一緒に入ってますね。これはGitのサイトにRPMとして存在していたような気がしますので、この二つを取ってきて入れれば依存性の問題も解決しつつインストールできたのかもしれません。

Gitを軽く触ってみる

生成してまだ何にもしていないRailsアプリをとりあえずGitに入れておこう。

$ git init
Initialized empty Git repository in /home/xxx/work/rails/blog_app/.git/
$ git add -A
$ git commit -m "created new Rails App."
[master (root-commit) 884ef4f] created new Rails App.
 Committer: xxx <xxx@aaa.bbb.jp>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <you@example.com>'

 39 files changed, 10212 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 Gemfile
 create mode 100644 README
 create mode 100644 Rakefile
 create mode 100644 app/controllers/application_controller.rb
 create mode 100644 app/helpers/application_helper.rb
 create mode 100644 app/views/layouts/application.html.erb
 create mode 100644 config.ru
 create mode 100644 config/application.rb
 create mode 100644 config/boot.rb
 create mode 100644 config/database.yml
 create mode 100644 config/environment.rb
 create mode 100644 config/environments/development.rb
 create mode 100644 config/environments/production.rb
 create mode 100644 config/environments/test.rb
 create mode 100644 config/initializers/backtrace_silencers.rb
 create mode 100644 config/initializers/inflections.rb
 create mode 100644 config/initializers/mime_types.rb
 create mode 100644 config/initializers/secret_token.rb
 create mode 100644 config/initializers/session_store.rb
 create mode 100644 config/locales/en.yml
 create mode 100644 config/routes.rb
 create mode 100644 db/seeds.rb
 create mode 100644 doc/README_FOR_APP
 create mode 100644 lib/tasks/.gitkeep
 create mode 100644 public/404.html
 create mode 100644 public/422.html
 create mode 100644 public/500.html
 create mode 100644 public/favicon.ico
 create mode 100644 public/images/rails.png
 create mode 100644 public/index.html
 create mode 100644 public/javascripts/application.js
 create mode 100644 public/javascripts/controls.js
 create mode 100644 public/javascripts/dragdrop.js
 create mode 100644 public/javascripts/effects.js
 create mode 100644 public/javascripts/prototype.js
 create mode 100644 public/javascripts/rails.js
 create mode 100644 public/robots.txt
 create mode 100644 public/stylesheets/.gitkeep
 create mode 100755 script/rails
 create mode 100644 test/performance/browsing_test.rb
 create mode 100644 test/test_helper.rb
 create mode 100644 vendor/plugins/.gitkeep

眺めてみると、いろんなファイルあるな。favicon.icoとかrobots.txtまであるんだね。

Gitの使い方については尊敬する結城さんのサイトでさらりと確認。
Gitの基礎練習