Enseignements

Notes d'installation de Linux pour les TP IFPS a partir du Cours 5

Cette page est obsolete!!

En 2013, nous utilisons rbenv au lieu rvm. Voir les notes d’installation avec rbenv ici

Installation Rails / XUbuntu

Compte tenu des difficultés rencontrées pour installer ubuntu 12.04 LTS dans vmplayer, et compte-tenu de la mauvaise ergonomie de cette version, je choisis d’installer XUbuntu 12.04 LTS:

  • lancement de vmplayer
  • Choix de l’image iso d’installation XUbuntu
  • changement config par defaut pour 1Go ram sur une machine hote avec 4Go
  • Choix du clavier francais
  • Attendre …
  • apres reboot,
    • apt-get install gdm (selectionner gdm au lieu de lightgdm)
    • /sbin/shutdown -r now
  • apres reboot
    • se connecter (l3info/l3info)
    • Choisir “Use default config” pour le panel
    • Cliquer en haut a droite sur l’etoile rouge “install all update” pour mettre le systeme a jour…
    • MaJ des vmtools avec apt-get (paquetages open-vm-tools)
    • reboot
    • Desinstall gdm, reboot, reinstall gdm, reboot

L’installation automatique des outils vmware ne fonctionnant pas, on choisit d’installer les outils open-vm-xxx:

$ apt-get install open-vm-tools open-vm-tools-dbg open-vm-tools-dev open-vm-toolbox open-vm-dkms

On poursuit avec la procédure d’installation décrite dans les cours numéro 1 et 3:

  • Installation curl et rvm
$ sudo apt-get install curl
$ curl -L get.rvm.io | bash -s stable

L’installation de rvm ajoute l’instruction pour lire le script rvm dans le fichier .bash_login aui n’est lu que lors du login. Il est donc préférable de quitter la session et de se reconnecter avant de poursuivre…

  • Mise a niveau de rvm
$ rvm get stable
  • Installation editeur
$ sudo apt-get install gedit
  • Installation de ruby 1.9.3
$ rvm install 1.9.3
No binary rubies available for: ubuntu/12.04/i386/ruby-1.9.3-p286.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /home/l3info/.rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  460k  100  460k    0     0   159k      0  0:00:02  0:00:02 --:--:--  197k
Extracting yaml-0.1.4.tar.gz to /home/l3info/.rvm/src
Configuring yaml in /home/l3info/.rvm/src/yaml-0.1.4.
Compiling yaml in /home/l3info/.rvm/src/yaml-0.1.4.
Installing yaml to /home/l3info/.rvm/usr
Installing Ruby from source to: /home/l3info/.rvm/rubies/ruby-1.9.3-p286, this may take a while depending on your cpu(s)...
ruby-1.9.3-p286 - #downloading ruby-1.9.3-p286, this may take a while depending on your connection...
ruby-1.9.3-p286 - #extracting ruby-1.9.3-p286 to /home/l3info/.rvm/src/ruby-1.9.3-p286
ruby-1.9.3-p286 - #extracted to /home/l3info/.rvm/src/ruby-1.9.3-p286
ruby-1.9.3-p286 - #configuring
ruby-1.9.3-p286 - #compiling
ruby-1.9.3-p286 - #installing 
Retrieving rubygems-1.8.24
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  371k  100  371k    0     0  2010k      0 --:--:-- --:--:-- --:--:-- 2651k
Extracting rubygems-1.8.24 ...
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.3-p286 ...
Installation of rubygems completed successfully.
Saving wrappers to '/home/l3info/.rvm/bin'.
ruby-1.9.3-p286 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p286 - #importing default gemsets (/home/l3info/.rvm/gemsets/)
Install of ruby-1.9.3-p286 - #complete
  • On indique a rvm que l’on souhaite travailler avec cette nouvelle version de ruby en créant un nouveau gemset
rvm use 1.9.3@rails3tutorial2ndEd --create --default

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

L’erreur précédente vient du fait que, à nouveau, il faut recharger le configuration de rvm en lisant le .bash_login. Une solution simple consiste à recharger un shell en mode login:

$ bash -l
$ rvm use 1.9.3@rails3tutorial2ndEd --create --default
Using /home/l3info/.rvm/gems/ruby-1.9.3-p286 with gemset rails3tutorial2ndEd
  • Mise à jour des gems système:
$ gem update --system 1.8.24
/home/l3info/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
ERROR:  Loading command: update (LoadError)
    cannot load such file -- zlib
ERROR:  While executing gem ... (NameError)
    uninitialized constant Gem::Commands::UpdateCommand

ERREUR. On corrige de la façon suivante:
1. on install le paquetage yaml

 $ rvm pkg install libyaml
Fetching yaml-0.1.4.tar.gz to /home/l3info/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /home/l3info/.rvm/src
Configuring yaml in /home/l3info/.rvm/src/yaml-0.1.4.
Compiling yaml in /home/l3info/.rvm/src/yaml-0.1.4.
Installing yaml to /home/l3info/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

2. On installe le paquetage zlib
(on réinstallera ruby comme demandé un peu plus tard)

$ rvm pkg install zlib
Fetching zlib-1.2.7.tar.gz to /home/l3info/.rvm/archives
There is no checksum for 'http://prdownloads.sourceforge.net/libpng/zlib-1.2.7.tar.gz' or 'zlib-1.2.7.tar.gz', it's not possible to validate it.
If you wish to continue with unverified download add '--verify-downloads 1' after the command.


Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Hum, il semble qu’il y ait un problème de checksum avec ce paquetage, on décide de passer outre et d’installer sans vérifier les checksum, comme suggéré:

$ rvm pkg install zlib --verify-downloads 1
Fetching zlib-1.2.7.tar.gz to /home/l3info/.rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  547k  100  547k    0     0   116k      0  0:00:04  0:00:04 --:--:--  147k
No checksum for downloaded archive, recording checksum in user configuration.
Extracting zlib-1.2.7.tar.gz to /home/l3info/.rvm/src
Configuring zlib in /home/l3info/.rvm/src/zlib-1.2.7.
Compiling zlib in /home/l3info/.rvm/src/zlib-1.2.7.
Installing zlib to /home/l3info/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Cette fois ça marche!
3. On réinstalle ruby comme demandé:

$ rvm reinstall all --force
Removing /home/l3info/.rvm/src/ruby-1.9.3-p286...
Removing /home/l3info/.rvm/rubies/ruby-1.9.3-p286...
No binary rubies available for: ubuntu/12.04/i386/ruby-1.9.3-p286.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /home/l3info/.rvm/rubies/ruby-1.9.3-p286, this may take a while depending on your cpu(s)...
ruby-1.9.3-p286 - #downloading ruby-1.9.3-p286, this may take a while depending on your connection...
ruby-1.9.3-p286 - #extracting ruby-1.9.3-p286 to /home/l3info/.rvm/src/ruby-1.9.3-p286
ruby-1.9.3-p286 - #extracted to /home/l3info/.rvm/src/ruby-1.9.3-p286
ruby-1.9.3-p286 - #configuring
ruby-1.9.3-p286 - #compiling
ruby-1.9.3-p286 - #installing 
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.3-p286 ...
Installation of rubygems completed successfully.
Saving wrappers to '/home/l3info/.rvm/bin'.
ruby-1.9.3-p286 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p286 - #importing default gemsets (/home/l3info/.rvm/gemsets/)
Install of ruby-1.9.3-p286 - #complete 
Making gemset ruby-1.9.3-p286 pristine.
Making gemset ruby-1.9.3-p286@global pristine.
Making gemset ruby-1.9.3-p286@rails3tutorial2ndEd pristine.

4. Après cette réinstallation réussie, on peut retenter la commande rvm qui avait échoué:

$ rvm use 1.9.3@rails3tutorial2ndEd --create --default
Using /home/l3info/.rvm/gems/ruby-1.9.3-p286 with gemset rails3tutorial2ndEd

Ca marche, problème résolu.

Après cette installation réussie de ruby et création du gemset, il vaut quitter la session et se reconnecter, pour ^etre sur d’utiliser un environement propre.

  • On crée le fichier .gemrc:
$ cat > ~/.gemrc
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
^D
  • On essaie d’installer rails 3.2.8 et on obtient encore une erreur a propos de yaml. Grrr. On interrompt l’installation avec Ctrl-C.
$ gem install rails -v 3.2.8
/home/l3info/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
^CERROR:  Interrupted

Essayons de comprendre: nous avons réinstallé, yaml, puis ruby et maintenant yaml manque à nouveau. Voyons de plus près le fonctionnelent de la commande rvm pkg :

$ rvm pkg help

Usage:

    rvm pkg {install,uninstall} {readline,iconv,curl,openssl,zlib,autoconf,ncurses,pkgconfig,gettext,glib,mono,llvm,libxml2,libxslt,libyaml}

ree_dependencies installs zlib, ncurses, readline, openssl and iconv in this order.
Still need to add --with-readline-dir=/home/l3info/.rvm/usr --with-iconv-dir=/home/l3info/.rvm/usr
 --with-zlib-dir=/home/l3info/.rvm/usr --with-openssl-dir=/home/l3info/.rvm/usr to rvm install ree

Starting with ruby **1.9.3** it is enough to use --with-opt-dir=/home/l3info/.rvm/usr for all the packages.

La solution semble etre proposée dans le dernier commentaire. Essayons (en remplacant le chemin du homedir par la variable HOME plus portable):

$ rvm pkg install zlib --with-opt-dir=$HOME/.rvm/usr
Fetching zlib-1.2.7.tar.gz to /home/l3info/.rvm/archives
Extracting zlib-1.2.7.tar.gz to /home/l3info/.rvm/src
Configuring zlib in /home/l3info/.rvm/src/zlib-1.2.7.
Compiling zlib in /home/l3info/.rvm/src/zlib-1.2.7.
Installing zlib to /home/l3info/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Faire de meme avec libyaml.

Puis reinstall de ruby et rails:

$ rvm reinstall all --force --with-opt-dir=$HOME/.rvm/usr
$ gem install rails -v 3.2.8

Et… ça marche sans erreur! OUF!
On peut terminer l’installation comme décrit au début du chapitre 3:

$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev
$ sudo apt-get install nodejs
$ gem install execjs

Essayons de créer une première app:

$ mkdir rails_project
$ cd rails_project/
$ rails new first_app

La création se termine par un nouveau message d’erreur:

Fetching gem metadata from https://rubygems.org/.
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your
Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL
using RVM are available at rvm.io/packages/openssl.

Il faut donc recompiler à nouveau ruby, après installation de la librairie manquante:

$ rvm pkg install openssl --with-opt-dir=$HOME/.rvm/usr
$ rvm reinstall all --force --with-opt-dir=$HOME/.rvm/usr

Puis on détruit le répartoire du nouveau projet avant de le recréer:

$ rm -rf first_app
$ rails new first_app

Et cette fois la création se passe sans erreur.

Utilisation de la console

Pour utiliser la commande rails console il faut ajouter le gem suivant dans son Gemfile: rb-readline et lancer la commande bundle install

Page d’Accueil

Enseignements 2017-18

Enseignements Antérieurs

Recherche…

edit SideBar

Blix theme adapted by David Gilbert, powered by PmWiki