bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)

Problem

When trying to connect with ssh to a linux (debian- ubuntu) server you get the following error:

bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)

Solution

The reason is that the server is missing the en_US locale that your client is trying to use to connect to the server.
Login to the server and by using sudo (or su) run the following to install the missing en_US locale and make sure that you leave default to ‘None’ as described here:

dpkg-reconfigure locales

Can’t install RMagick 2.13.1. Can’t find Magick-config

Problem

You are trying to install rmagick in an Ubuntu 12.04 virtual box, but you get the following error:

Can't install RMagick 2.13.1. Can't find Magick-config

Solution

Make sure you install both the imagemagick and the libmagickwand-dev packages with either apt-get :

sudo apt-get install imagemagick libmagickwand-dev

or in a puppet script as:

package {
  "imagemagick":
    ensure => installed
}

package {
  "libmagickwand-dev":
    ensure  => installed
}

Adding timezone information in MySQL

Problem
You would like to convert times in MySQL with the CONVERT_TZ function and to be able to use timezone names (ie CE).

Problem

  1. Find out if your MySQL includes timezone information as it is not included by default. Log in and run : select count(*) from mysql.time_zone_name;
  2. If the result is 0 then the timezone information is not included
  3. Log out from your MySQL server on the command prompt and upgrade your server with: mysql_upgrade -p
  4. On the command prompt again load up the table with the data (linux server): mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql/li>
  5. Login to your MySQL server again and run the first query: select count(*) from mysql.time_zone_name;

Using Postfix to send out emails from development environment in Rails

Problem

You want to be able to send emails from your development enironment using Postfix in your (K)Ubuntu pc.

Solution

First you would need to install postfix:

sudo apt-get install postfix

and then you would need to change an option in postfix to not use tls, so change /etc/postfix/main.cf:

sudo vi /etc/postfix/main.cf

and change the smtpd_use_tls from yes to no:

smtpd_use_tls=no

restart your postfix server:

sudo /usr/sbin/postfix reload

and then setup your config/development.rb as follows:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:                 "127.0.0.1",
  port:                    25,
  enable_starttls_auto:    false
}

Command line mail message with postfix in (K)ubuntu

Problem

You have installed postfix in your local development machine (sudo apt-get install postfix), and you want to test sending emails from the command line using mail email_address@someone.com

 

Solution

You would first need to install the mailutils package:

sudo apt-get install mailutils

then you can send an email by:

mail email_name@example.com
CC: (leave blank)
Subject: Test subject
Main message body

and you can send it by pressing Ctrl+D

Creating a Vagrant Box with Debian Lenny 32, rvm and Ruby 1.9.3

As an addition to the excellent beta book ‘Deploying Rails’, as I had problems using the suggested lucid64 image, I’ve tried to install a debian lenny 32 image with rvm and Ruby 1.9.3.

The steps needed are listed below

 

  1. Download the lenny package:
    localhost$ vagrant box add debian-lenny-32 https://s3-eu-west-1.amazonaws.com/glassesdirect-boxen/debian/debian_lenny_32.box
  2. Make a new directory for the virtual box:
    localhost$ mkdir -p ~/deployingrails/lenny32
  3. change into created directory and create the Vagrant file:
    localhost$ cd ~/deployingrails/lenny32
    vagrant init
  4. change the Vagrant file to use the virtual box we have downloaded:
    Vagrant::Config.run do |config|
      config.vm.box = "lenny32"
    end
  5. Start the VM:
    localhost$ vagrant up
  6. If there is a warning about the Guest additions here install the latest guest additions by following the description here, but only use the update and upgrade steps as:
    localhost$ vagrant ssh
    vagrant$ sudo apt-get update
    vagrant$ sudo apt-get upgrade
  7. After finishing the upgrade logout (exit) from the VM and issue the command to restart the VM:
    localhost$ vagrant reload
  8. login to the VM again:
    localhost$ vagrant ssh
  9. Install curl to be able to download the installation script for:
    vagrant$ sudo apt-get install curl
  10. Download and install rvm by using the script described here http://beginrescueend.com/rvm/install/ :
    vagrant$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
  11. Add the loading of the RVM function into .bashrc, by running the following in the command prompt:
    vagrant$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
  12. Reload the bashrc file:
    vagrant$ source ~/.bashrc
  13. Make sure that the rvm is loaded as function:
    vagrant$ type rvm | head -1
    rvm is a function
  14. Run the rvm requirement to see the needed libraries and then run the suggested ones (except libreadline6 and libreadline6-dev that are not there in debian):
    vagrant$ sudo apt-get install build-essential openssl curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
  15. Install Ruby 1.9.3 :
    vagrant$ rvm install ruby-1.9.3
  16. Use the ruby 1.9.3 as default:
    vagrant$ rvm use 1.9.3 --default
  17. Finally create a new VM package to use in future:
    localhost$ vagrant package --output lenny32-rvm-ruby193
  18. And add it our box list:

    localhost$ vagrant box add lenny32-rvm-ruby193 lenny32-rvm-ruby193
    localhost$ vagrant box list

ERD diagrams in Ruby on Rails

Problem

You would like to have an ERD diagram of your database in your Ruby on Rails project.

Solution

You can install the Rails ERD from here, and install it by following the instructions.
For Ubuntu/debian systems should be:

sudo apt-get install graphviz

and then adding the gem to your Gemfile in the development section as:

group :development do
  gem "rails-erd", "~> 0.4.5"
end

You can then run bundle install to install the gem and rake erb to create the diagram pdf.