月別アーカイブ: 2016年6月

UbuntuでBootstrapを試してみる

Ubuntuの環境で、Bootstrapをインストールしてみます

■pills
ナビゲーション(錠剤:pills)

下記のような、を表示してみます。

1,を実施の後に、行って下さい。
http://getbootstrap.com/components/#nav-pills

スクリーンショット 2016-06-29 16:02:34

 

■tabs(タブ)
http://getbootstrap.com/components/#nav-tabs

■Breadcrumbs(パンくず)
http://getbootstrap.com/components/#breadcrumbs

■pagination(ページ付け)
http://getbootstrap.com/components/#pagination-default

■Pager(ページャ)
http://getbootstrap.com/components/#default-example

■Aligned links(並べたリンク)
http://getbootstrap.com/components/#aligned-links

■Available variations(各種のラベル)
http://getbootstrap.com/components/#available-variations

■Badges(バッジ、印)
http://getbootstrap.com/components/#badges

VirtualBox centos6.8で、Apache+Passenger+Sinatraでの環境構築

VirtualBox centos6.8で、Apache+Passenger+Sinatraでの環境構築
してみる

sudoを使えるようにする
使用できるか確認する

・結果表示
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for centos: ##←パスワードを入力
centos は sudoers ファイル内にありません。この事象は記録・報告されます。
[centos@localhost ~]$ 

使用できない

Passwordを入力

ALL=を検索する

root ALL=(ALL) ALL
の下に

ユーザー名 ALL=(ALL) ALLを追加する

vi のコマンドなので
iで、挿入モードとして
ユーザー名 ALL=(ALL) ALL
を入力し
[Esc]+:+wq+改行で上書き終了
suから抜ける

suから抜ける
もう一度ためして見る

・表示結果
[sudo] password for centos: 
bin   dev  home  lib64	     media  mnt  opt   root  selinux  sys  usr
boot  etc  lib	 lost+found  misc   net  proc  sbin  srv      tmp  var
[centos@localhost ~]$ 

できた。

必要なアプリをインストール

15分ぐらいかかります・・・・

・結果表示
Here's what you can expect from the installation process:
  
 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.
  :
  :
Press Enter to continue, or Ctrl-C to abort.
 
1を、選択
・結果表示
Use <space> to select.
If the menu doesn't display correctly, press '!'
  
 ‣ ⬢  Ruby
   ⬢  Python
   ⬡  Node.js
   ⬡  Meteor
 
entrで、進んで行く

エラーがでます

・結果表示
[root@localhost sina]# /etc/rc.d/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中: httpd: Syntax error on line 1010 of /etc/httpd/conf/httpd.conf: Cannot load /home/centos/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so into server: /home/centos/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so: cannot open shared object file: Permission denied

cannot open shared object file: Permission denied
Permission関係なので、SELinuxの設定を変えてみます

[root@localhost sina]# /etc/rc.d/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

apacheの起動はできた

http://localhost/にアクセスしてみます

エラーがでる

[root@localhost sina]# curl 'http://localhost/'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 80</address>
</body></html>
[root@localhost sina]# 

apacheのエラーログを調べてみる
まず、error_logのありかを調べる

・結果表示
/var/log/httpd/error_log

エラーを表示してみる

・表示結果
  :
    :
[Sat Jun 25 05:17:15 2016] [error] [client ::1] (13)Permission denied: access to / denied

(13)Permission denied: access to / denied
で、Googleに聞いてみる
ユーザホームディレクトリのパーミッションが原因のようだ

http://dqn.sakusakutto.jp/2010/05/apache_13permission_denied_acc.html
http://toybox-v2.blogspot.jp/2011/10/13permission-denied-access-to-denied.html
(13)Permission denied: access to hoge denied の対処

Permissionを変えてみる

まず、現状を調べる

・表示結果
合計 12
drwxr-xr-x.  3 root   root   4096  6月 22 05:18 2016 .
dr-xr-xr-x. 25 root   root   4096  6月 25 04:16 2016 ..
drwx------. 33 centos centos 4096  6月 25 05:00 2016 centos

実行権限を付与する

・表示結果
合計 12
drwxr-xr-x.  3 root   root   4096  6月 22 05:18 2016 .
dr-xr-xr-x. 25 root   root   4096  6月 25 04:16 2016 ..
drwxr-xr-x. 33 centos centos 4096  6月 25 05:00 2016 centos
[root@localhost sina]# 

実行権限が付与された

drwx------. 33 centos centos 4096  6月 25 05:00 2016 centos
  ↓↓
drwxr-xr-x. 33 centos centos 4096  6月 25 05:00 2016 centos

もう一度行ってみる

[root@localhost sina]# curl 'http://localhost/'
Hello World[root@localhost sina]#

うまく表示された

Firfoxからhttp://localhost/を呼んでも、うまくいった

再起動して確認してましす

必要はファイルなどは、保存後、アプリを終了しておいて、下さい。

リブートします

SELinuxを確認

[centos@localhost ~]$ getenforce
Enforcing
[centos@localhost ~]$ 

Enforcing → SELinux機能、アクセス制御が有効

無効に設定する

/etc/selinux/config
ファイルの
SELINUX=enforcing

SELINUX=disabled
に変更します

apacheの状態を調べる

httpd は停止しています
[centos@localhost ~]$ 

httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off

httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

レベル2から5がon(自動起動)になる

再度、リブートしてみます

SELinuxを確認

[centos@localhost ~]$ getenforce
Disabled
[centos@localhost ~]$ 

無効なのでOK

apacheの状態を調べる

[sudo] password for centos: 
httpd (pid  2021) を実行中...
[centos@localhost ~]$ 

実行中なのでOK

localhostにアクセスしてみる

[centos@localhost ~]$ curl 'http://localhost/'
Hello World[centos@localhost ~]$ 

接続できた

Firfox
http://localhost/
にアクセスする

Hello World

無事表示されました

passenger+sinatraで、Documenの置き場所をhomeに変える

前々回

apache+passenger+sinatraにて、
環境を構築しましたが、

コンテンツの置き場所が
/root/
で、権限がo+x
のままだと、プログラムの作成、編集が、面倒です。

また、
/root/の権限がそのままというのも、
少々不安な感じがします。

このため、コンテンツの置き場所を

/home/(user)/sina

に変更するしてみましょう

ユーザ権限にて

cd
pwd
・結果表示
/home/(user)
cd
mkdir sina
cd sina
echo "#coding: utf-8"    >app.rb
echo "require 'sinatra'" >>app.rb
echo "get '/' do"        >>app.rb
echo "'Hello World'"     >>app.rb
echo "end"               >>app.rb
echo "require File.expand_path(File.dirname(__FILE__)) + '/app'"  >config.ru
echo "run Sinatra::Application"                                   >>config.ru
mkdir public
mkdir tmp
touch tmp/always_restart.txt

/etc/httpd/conf/httpd.confを変更

su
権限にて
ファイル
/etc/httpd/conf/httpd.conf

DocumentRoot /root/sina/public
の部分を
DocumentRoot /home/(user)/sina/public
に変更

vi /etc/httpd/conf/httpd.conf
/etc/rc.d/init.d/httpd restart
curl 'http://localhost/'

しかし、エラーになる
エラーの内容を確認
apacheのエラーログの場所を探す

find / -name error_log
・結果表示
/var/log/httpd/error_log

エラーの内容を確認する

cat /var/log/httpd/error_log
・内容表示
:
Could not find rake-11.2.2 in any of the sources (Bundler::GemNotFound)
:

/home/(user)/ap/public
にも、Bundlerなどが必要・・・・・
.Bundler(隠しファイル)
なども、必要なので
一括複写する

cp -R /root/sina /home/(user)/sina

はじめから、こうすればよかった。。。

apacheの再起動

/etc/rc.d/init.d/httpd restart

確認

curl 'http://localhost/'

うまくいった。

suで、複写したので、
home側での権限などが心配なので、
ユーザ権限にもどって、作りなおしてみる

$cd
$cp -R /home/(user)/sina /home/(user)/sinatra

/etc/httpd/conf/httpd.conf

DocumentRoot /home/(user)/sina/public

DocumentRoot /home/(user)/sinatra/public
に変更し、apache再起動
/etc/rc.d/init.d/httpd restart
表示確認
curl ‘http://localhost/’

うまくいった。

Gitの操作手順(bitbucket版)

Gitの基本操作をまとめました

接続は、httpsにより、問い合わせに対する
パスワード入力となっています。

手順

1,bitbucketのWebにて、レポジトリを新規に作る(例:test)
2,ローカルにデータを作成し、サーバに上げる(push)

作業エリアを作成

mkdir work1
cd work1
git init

レポジトリを追加

git remote add origin https://username@bitbucket.org/username/repojname.git

(userがyamada レポジトリ名がtestなら

git remote add origin https://yamada@bitbucket.org/yamada/test.git

データを作成(bitbucketの説明コードを引用)

echo "Tarou Yamada" >> contributors.txt
git add contributors.txt
git commit -m 'Initial commit with contributors'
git push -u origin master

パスワードを聞かれる
サーバに転送できる

サーバ側を確認する

3,さらに、内容を変更する

echo "next text" >> sample.txt
git add sample.txt
git commit -m 'next data'
git push -u origin master

サーバ側に、さらに追加されたか、確認する

4,別のエリアにデータを取り込む(clone)

作業エリアを作成

mkdir work2
cd work2

レポジトリを取り込む

git clone https://username@bitbucket.org/username/repojname.git

(userがyamada レポジトリ名がtestなら

git clone https://yamada@bitbucket.org/yamada/test.git

)

取り込んだ、レポジトリ名のフォルダに入る

cd repojname

(レポジトリ名がtestなら

cd test

)

内容を変更する

echo "next text2" >> sample2.txt
git add sample2.txt
git commit -m 'next data2'
git push -u origin master

パスワードを聞かれる
サーバに転送できる

サーバ側を確認する

5,サーバ側の変更内容の最新をローカルに反映する
本当は、ローカルと、サーバ側の更新のタイミングと
その、反映方法によりことなるが、
ローカル側は、変更なしで(本番環境)
サーバ側のデータを反映(リリース)する場合

サーバ側のデータを、変更する

cd work2
git checkout master
git pull origin master

本来は、サーバとローカルの状態、
複数ユーザ間での管理など、
ここで、使い分ける事で、
いろいろな事ができるのですが・・・・

6,その他
addとcommit を同時に

git commit -am "mesage"

VirtualBoxにCentOS6.8の環境を構築

VirtualBox CentOS6.8の構築の手順をまとめました

1,インストール用DVDのisoファイルをダウンロード
  ■ インストール用DVDファイルは何処にあり、どれが必要か?
  http://isoredirect.centos.org/centos/6/isos/x86_64/
にある
  CentOS-6.8-x86_64-bin-DVD1.iso
が、必要。

2,VirtualBoxに、セットする
  ■ 設定方法は?
  以下の手順を参考に
  https://blog.apar.jp/linux/402/

3,インストールする
  ■ インストールの設定は?
  以下を参考に
   http://win.just4fun.biz/%E4%BB%AE%E6%83%B3%E5%8C%96%E9%96%A2%E9%80%A3%E3%82%BD%E3%83%95%E3%83%88/VirtualBox%E3%81%A7CentOS6%E3%82%92%E5%8B%95%E3%81%8B%E3%81%9D%E3%81%86.html

4,Firfoxで、外部に接続する
  ■ 外部のネットにつながらない?、Firfoxが開かない
  以下を参考に
 http://kb.seeck.jp/archives/4552

5,GuestAddtionsをインストールして、マウスの操作をスムーズにする
  ■ マウスが、HostとGestで操作がしにくい
  Gest(仮想側)から、Hostへ戻すには「右側のCTRLキー」を押すことで、切り替わる
  ただし、操作が面倒、GuestAddtionsをインストールをGest(仮想側)にインストールする
  ことで、操作性が上がります(切り替えなしで可能に)
VirtalBoxのメニューから、「デバイス」>「Guest Additionsのインストール」
仮想端末から

 
su
cd /media
ls
cd DVDメディア
./VBoxLinuxAdditions.run
yum install kernel-devel-2.6.32-504.3.3.el6.i686
yum -y install kernel-devel
yum -y install gcc
./VBoxLinuxAdditions.run

  GuestAddtionsをインストールは下記を参考に
 http://www.maruweb.jp.net/wp/?p=1916

6,VirtualBoxでOS間のクリップボードを共有する方法
  ■ Gest(仮想側)と、Hostで、クリップボードを共有に(コピペを可能に)
GuestAddtionsをインストールをした後、設定で可能に、下記を参考に
 http://pc-karuma.net/virtualbox-clipboard-share/

7,起動時の、ネットワーク(eth0)の自動接続
  ■ 起動時のeth0の接続(CentOSの設定)
  /etc/sysconfig/network-scripts/ifcfg-eth0
  の
  ONBOOT=no
  を
  ONBOOT=yes
  に、変更

  立ち上げ後
  su
  vim /etc/sysconfig/network-scripts/ifcfg-eth0
  にて、変更(編集)

以上です。

仮想環境にて、
CentOS6.8を楽しんで下さい。

CentOS6.7にpassengre+sinatra

CentOS6.7にpassengre+sinatra
を、なるべく、一括でできるようにまとめてみました

必要なアプリをインストール

yum -y install git gcc gcc-c++ libcurl-devel httpd httpd-devel openssl-devel readline-devel zlib-devel
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
mkdir ~/.rbenv/plugins
cd ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git
rbenv install 2.2.5
rbenv shell 2.2.5
gem install bundler
cd
mkdir sina
cd sina
mkdir vendor
mkdir vendor/bundle
mkdir public
mkdir tmp
touch tmp/always_restart.txt
bundle init
echo 'gem "sinatra"' >> Gemfile
echo 'gem "passenger"' >> Gemfile
bundle install --path vendor/bundle
bundle exec passenger-install-apache2-module
・結果表示
Here's what you can expect from the installation process:
 
 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.
  :
  :
Press Enter to continue, or Ctrl-C to abort.

1を、選択
・結果表示
Use <space> to select.
If the menu doesn't display correctly, press '!'
 
 ‣ ⬢  Ruby
   ⬢  Python
   ⬡  Node.js
   ⬡  Meteor

entrで、進んで行く
bundle exec passenger-install-apache2-module --snippet >> /etc/httpd/conf/httpd.conf
echo "DocumentRoot /root/sina/public" >> /etc/httpd/conf/httpd.conf
echo "#coding: utf-8"    >app.rb
echo "require 'sinatra'" >>app.rb
echo "get '/' do"        >>app.rb
echo "'Hello World'"     >>app.rb
echo "end"               >>app.rb
echo "require File.expand_path(File.dirname(__FILE__)) + '/app'"  >config.ru
echo "run Sinatra::Application"                                   >>config.ru
/etc/rc.d/init.d/httpd restart
getenforce
Enforcing

setenforce 0 

getenforce
Permissive
curl 'http://localhost/'
chmod o+x "/root"

curl 'http://localhost/'
Hello World

■確認
いまく、いかない時には
以下の内容を確認してください。

path

cd
cd sina
pwd

・結果表示
/root/sina

ファイルの内容1

cd
cd sina
ls
・結果表示
Gemfile  Gemfile.lock  app.rb  config.ru  public  tmp  vendor

ファイルの内容2

ls tmp
・結果表示
always_restart.txt

appの内容

cat app.rb
・結果表示
#coding: utf-8
require 'sinatra'
get '/' do
'Hello World'
end

config.ruの内容

cat config.ru
・結果表示
require File.expand_path(File.dirname(__FILE__)) + '/app'
run Sinatra::Application

httpd.confの内容

cat /etc/httpd/conf/httpd.conf
・結果表示(終わりの行)
  :
#</VirtualHost>
DocumentRoot /root/sina/public
LoadModule passenger_module /root/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.28/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /root/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.28
  PassengerDefaultRuby /root/.rbenv/versions/2.2.5/bin/ruby
</IfModule>

SELinuxの内容

getenforce
・結果表示
Permissive

/rootの権限

ls /root -l
・結果表示
drwxr-xr-x. 6 root root  4096  6月 22 09:17 2016 sina

conohaのクラウド centOS 6.7に、sinatoraをインスツール

Ubuntu16でRubyを使ってみる

を、元に、centOS 6.7にsinatraをインスツールしてみた。

■gitのインストール
gitのインストールしているか確認

git --version
・結果表示
-bash: git: コマンドが見つかりません

gitのがないのでインストール

yum -y install git

git --version
・結果表示
git version 1.7.1

■benv のインストール

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bashrc

echo 'eval "$(rbenv init -)"' >> ~/.bashrc

シェルを再起動

source ~/.bashrc

インストールの確認

type rbenv
・結果表示
rbenv is a function
rbenv () 
{ 
    local command;
    command="$1";
    if [ "$#" -gt 0 ]; then
        shift;
    fi;
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
        ;;
        *)
            command rbenv "$command" "$@"
        ;;
    esac
}

■ruby-build のインストール

mkdir ~/.rbenv/plugins
cd ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git

■ruby のインストール
インストール可能な、最新バージョンを確認

rbenv install -l

2.2.5をインストール

rbenv install 2.2.5

エラーになった

・結果表示
:
checking for gcc... no

gccがないので、の追加

yum -y install gcc

再度

rbenv install 2.2.5

エラーになった

・結果表示
:
Try running <code>yum install -y openssl-devel readline-devel zlib-devel</code> to fetch missing dependencies.

指示にしたが、追加

yum install -y openssl-devel readline-devel zlib-devel

再度

rbenv install 2.2.5

インストールできた

インストールした、Rubyのバージョンを確認

rbenv shell 2.2.5
ruby -v

ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-linux]

■bundler のインストール

rbenv shell 2.2.5
gem install bundler

■sinatra のインストール

プロジェクト用エリア(フォルダ:sina)を作成

cd
mkdir sina
cd sina

Gemfileを作成

bundle init

Gemfileにgem ‘sinatra’を追加

cat Gemfile
echo 'gem "sinatra"' >> Gemfile
cat Gemfile
mkdir vendor
mkdir vendor/bundle

bundle で、Gemfileを実行

bundle install --path vendor/bundle

■サンプルAPの作成
app.rbを作成

echo "#coding: utf-8"    >app.rb
echo "require 'sinatra'" >>app.rb
echo "get '/' do"        >>app.rb
echo "'Hello World'"     >>app.rb
echo "end"               >>app.rb

cat app.rb

■実行確認

bundle exec ruby app.rb

INFO  WEBrick::HTTPServer#start: pid=30947 port=4567

別の端末を開く

curl 'http://localhost:4567/'
・結果表示
Hello World

できた

■passengerで接続

■Gemでpassengerをインストール
Gemfileにgem ‘passenger’を追加

cd
cd sina

cat Gemfile
echo 'gem "passenger"' >> Gemfile
cat Gemfile

rbenv shell 2.2.5
bundle install

■passenger-install-apache2-moduleをインストール

bundle exec passenger-install-apache2-module
・結果表示
Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.
  :
  :
Press Enter to continue, or Ctrl-C to abort.

1を、選択

・結果表示
Use <space> to select.
If the menu doesn't display correctly, press '!'

 ‣ ⬢  Ruby
   ⬢  Python
   ⬡  Node.js
   ⬡  Meteor

entrで、進んで行く

エラーになるので、一度中断し
指摘された、不足のアプリケーションを追加

yum -y install gcc-c++ libcurl-devel httpd httpd-devel

再度

bundle exec passenger-install-apache2-module

インストールできた

apacheに設定を追加

bundle exec passenger-install-apache2-module --snippet >> /etc/httpd/conf/httpd.conf
echo "DocumentRoot /root/sina/public" >> /etc/httpd/conf/httpd.conf

アプリケーション設置用エリアを作成

mkdir /root/sina/public
mkdir /root/sina/tmp

config.ruを作成

echo "require File.expand_path(File.dirname(__FILE__)) + '/app'"  >/root/sina/config.ru
echo "run Sinatra::Application"                                   >>/root/sina/config.ru

アプリケーション修正時の自動リロードを指定

touch /root/sina/tmp/always_restart.txt

apacheの設定ファイルの整合性を確認

apachectl configtest

Syntax OKなので、起動してみる

・結果表示
httpd: apr_sockaddr_info_get() failed for 133-130-108-243
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK

apacheを起動

/etc/rc.d/init.d/httpd restart

動作を確認してみる

curl 'http://localhost/'
・結果表示
  :
<p>You don't have permission to access /
on this server.</p>
  :

権限がまずいとのこと
権限を変更

chmod o+x "/root"

再度を確認してみる

curl 'http://localhost/'
・結果表示
Hello World

うまくいった。。

Apacheー>Passengerー>Sinatra ができた。

Ubuntu16でvisualrubyをインストール

Ubuntuの環境で、GUIアプリケーションを
Rubyで開発するために
visualrubyをインストールしてみた

visualrubyは、フォームをGUIで、作成し、プログラムを開発するものです
VisualBaice,VisualStudioをイメージしてもらうといいでしょう

HP
http://visualruby.net

■ゼロベースからの手順をまとめる
1,Git のインストール
2.rbenv のインストール
3.ruby-build のインストール
4.ruby のインストール
5.bundler のインストール
6.visualruby のインストール
7.visualruby の起動、サンプル実行
8.glade のインストール
9.visualrubyからのglade起動設定
10.新規プログラム作成

1から5は
「Ubuntu16でRubyを使ってみる」

Ubuntu16でRubyを使ってみる


と、重複しますが、手順をわかりやすくするため
再度掲載しました

1.Git のインストール

sudo apt-get update
sudo apt-get install git

もし、
/var/lib/apt/lists/ をロックできません
/var/lib/apt/dpkg/ をロックできません
と、表示された場合は

sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock

2.rbenv のインストール

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

シェルを再起動

source ~/.bashrc

インストールの確認

type rbenv


「rbenv は関数です」と表示されればインストール完了

3.ruby-build のインストール

mkdir ~/.rbenv/plugins

cd ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git

4.ruby のインストール
インストール可能な、最新バージョンを確認

rbenv install -l

2.2.5をインストール

rbenv install 2.2.5

エラーになった

:
Try running `apt-get install -y libssl-dev libreadline-dev zlib1g-dev

とのことなので、

sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev

の、のち、再度

rbenv install 2.2.5

を、行う

インストールされたRubyのバージョンを確認

ruby -v

5.bundler のインストール

rbenv shell 2.2.5
gem install bundler

6.visualruby のインストール

プロジェクト用エリア(フォルダ:vruby)を作成

cd
mkdir vruby
cd vruby

Gemfileを作成

bundle init

vruby/Gemfile
という、ファイルが作成される
エディタで、Gemfileを開
gem ‘visualruby’を追加
する

source "https://rubygems.org"
gem 'visualruby'

# gemを入れるディレクトリを作成

mkdir vendor
mkdir vendor/bundle

bundle で、Gemfileを実行

bundle install --path vendor/bundle

7.visualruby の起動、サンプル実行
visualrubyを起動する

cd
cd vruby
rbenv shell 2.2.5
bundle exec vr

../example/all_widgets
を選択し「open」を、押下
メニューの「Run」を、押下し
アイアらしい
新しい画面が開く事を確認する
右上の✕、押下で終了
File>Quitで終了

8.glade のインストール
フォームをデザインするツールを「glade」をインスツールする
ブラウザで、
Ubuntu、パッケージサイトを開く

http://packages.ubuntu.com/ja/precise/glade-gtk2

から、glade-gtk2をダウンロード
amd64ならば
http://packages.ubuntu.com/ja/precise/amd64/glade-gtk2/download
から、ダウンロード
端末から、ダウンロードフォルダーに移動してインストール

cd
cd ダウンロード 
sudo dpkg -i glade-gtk2_3.8.0-0ubuntu4_amd64.deb

libgladeui-1-11がないと言われるので

sudo apt install libgladeui-1-11

リストにないといわれる場合(下記エラーが表示)

   :
   :
E: パッケージ 'libgladeui-1-11' はインストール候補ではありません

/etc/apt/sources.list
に、
deb http://us.archive.ubuntu.com/ubuntu vivid main universe
を、追加する

sources.listの編集は、root権限が必要
viの使用に慣れているなら
sudo cd /etc/apt/
sudo vi sources.list
で、先頭に
deb http://us.archive.ubuntu.com/ubuntu vivid main universe
を、追加

GUIで行うなら
sudo nautilus
で、root権限でnautilusを起動し
/etc/apt/sources.list
を、選択し、geditにて、開き
deb http://us.archive.ubuntu.com/ubuntu vivid main universe
を、追加し、上書き保存し、nautilusを終了

sudo apt-get update

もし、
/var/lib/apt/lists/ をロックできません
と、表示された場合は

sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock

再度、インストール

sudo apt-get update
sudo apt install libgladeui-1-11
sudo dpkg -i glade-gtk2_3.8.0-0ubuntu4_amd64.deb

にて、インストールができればOK

アプリケーション検索で
glade
を検索
Glade3インターフェース・デザイナという内容で登録されていれば
起動確認する

9.visualrubyからのglade起動設定
visualrubyを起動する

cd
cd vruby
rbenv shell 2.2.5
bundle exec vr

サンプルの
../example/listview
を選択し「Open」を、押下

Tool>GlobalSetting
を、選択
GladeCommandLine:
を、
「glade-gtk2」
を、選択し、「Try」で起動を確認
起動したgladeを、閉じ
設定画面を「Save」で終了する

左の、メニューTreeの
binの▶をクリックし展開し
gladeの▶をクリックし展開し
SongListVeiwGui.gladeをダブルクリックする
gladeが起動する
右サイドツリービューをクリックし、展開していく
Window1>hbox1>vBox1>hbox2>label1
まで、開きlabel1を選択する
プロパティのラベルを一部変更してみる

<big>ListView・・・・
→
<big>ーーーListView・・・・

保存を押して(ファイル>保存)、gladeを終了する
VisualRuby側で
「Run」
で、起動した時、デザインの修正内容が
反映していることを確認する

10.新規プログラム作成

File>NewProjet
で、新しいプロジェクトを作成する
プロジェクト名を「test001」として
「Create」を押す

「Run」により、起動を確認する
「Hello World」
のボタンを、押すと、表示が変わることを
動作を確認する

開いた画面を閉じ、プログラムを終了する

gladeの▶をクリックし展開し
デザインを変更する

ボタンを追加する

デザインを保存し終了する

MyClass.rb
を、修正し保存する

def before_show()
 @button1 = "こんにちは"
 @button2 = "世界"
end	
def button1__clicked(*args)
 @builder["button1"].label = @builder["button1"].label == "Hello World" ? "Goodbye World" : "Hello World"
 @builder["button2"].label = @builder["button1"].label == "Hello World" ? "Goodbye World" : "Hello World"
end
def button2__clicked(*args)
 @builder["button1"].label = "その1"
 @builder["button2"].label = "その2"
end

保存し、
プログラムを起動し、動作を確認する

その他

エディットボックスの場合
名前はentry番号となり
初期値は

def before_show()
 @entry1 = "こんにちは 世界1"
 @entry2 = "こんにちは 世界2"
end	

エディットボックス変更のイベントは

def entry1__changed(*args)
 @builder["entry2"].text = @builder["entry1"].text
end	

こんな感じ
上記の場合、エディットボックスの1,2の
初期値をそれぞれ、 “こんにちは 世界1”,”こんにちは 世界2”
とし、
entry1を変更すると、entry2も同じ内容になる

■注意点
1,VisualRubyとGTD+のバージョンと、gladeのバージョンの相性に注意
   → glade-gtk2_xx
2,Ubuntu16でのアプリケーションのインスツール設定
   → サードパーティがインスツールできない
3,gladeの使い勝手
   → VisualC#などのUiとは異なり、Itemドラッグ移動(微調整)はできない
     指定した箱の中に設置
     コンテナで、設置できる枠を作り、その枠の中に、コントロールを入れる

(慣れると、これも便利かも)

■参考
http://visualruby.net/index.html
https://github.com/Beagle123/visualruby

MySQLの現存するテーブルからcreate table文を起こす

既存のデータベースから、テーブルを作成するCREATE TABLE文を取得には

mysqlのコマンドの中で

SHOW CREATE TABLE テーブル名

で、できる

テーブルを追加する場合、既存のテーブルのCREATE TABLE文を取得して
それを、参考にし、新しいテーブル用のCREATE TABLE文を作ると便利である

また、データベース全体のCREATE TABLE文を取得するには
コマンドプロンプトから

mysqldump -u ユーザ名 -p --no-data データベース名

で、
パスワードを入力し、表示されます
ファイルに出力する場合には

mysqldump -u ユーザ名 -p --no-data データベース名 >dump.sql

可能です