Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Saturday, June 25, 2011

Getting Instiki wiki working on Ubuntu 11.04

Previous: Installing rvm on Ubuntu 11.04

I started by copying my backup of the whole directory .wiki from an external drive to /home/.wiki.
Then I ran the following commands:
rvm gem install bundler
sudo apt-get install
libxml2-dev
libxslt1-dev
sqlite3
libsqlite3-dev
cd .wiki
bundle
Bundler installed other components Instiki uses, including nokogiri, rubyzip, and sqlite3-ruby.

Instiki did not start, and reported this error:
/home/dave/.rvm/rubies/ruby-1.9.2-p180/lib
/ruby/1.9.1/psych.rb:148:in `parse':
couldn't parse YAML at line 18 column 14 (Psych::SyntaxError)


I found an explanation and workaround by vicvega on
Stack Overflow. I added the lines
require 'yaml'
YAML::ENGINE.yamler= 'syck'
at the top of Instiki's config/boot.rb file (just above the comment that reads, "Don't change this file!"), and Instiki started up clean. In a nutshell, the problem was that bundler uses psych as the default yaml parser, psych is not compatible with rails, and Instiki is a rails app.

In .bash_aliases I added a line to start the wiki conveniently:
alias wiki=~/.wiki/instiki


Next: Ubuntu 11.04 on Dell Vostro 3550 - FAIL

Sunday, April 11, 2010

Installing Rails

Previous: Installing MySQL and Ruby bindings

Use Gems to install Rails. Open a Terminal window and enter

cd ~
sudo gem install rails

If the installation succeeded, the following command will display version information:

rails -v

Next: Installing Ruby testing tools

Sunday, November 15, 2009

Installing Wubi on Acer Netbook

Previous: Firefox addon toolbar buttons not displayed

I've been using my Toshiba Satellite as my main workhorse, and my Acer Netbook as a system for running presentations at conferences and user group meetings and for clients. I took only the Acer with me on a business trip recently, and I became quite frustrated with using Windows XP all the time, rather than just for running presentations. Besides that, I missed having the usual tools available. I decided to load Ubuntu Linux on the Acer so I would have similar environments on both machines, and to avoid the hassle of using Windows.

I have a conventional dual-boot setup on the Toshiba. For the Acer, I decided to try Wubi, a program for Microsoft Windows that manages an Ubuntu dual boot for you, without your having to repartition the hard drive manually. I wanted to see how the user experience compares with the conventional dual boot setup.

Wubi install



First, I went to http://wubi-installer.org/ and downloaded the Wubi installer.

Next, I started Windows XP on the Acer and ran the installer, following the prompts as needed. Everything went smoothly.

After rebooting into Ubuntu Linux, Wubi copied the basic installation files and set up its pseudo partition. It installed 9.10 Karmic.

Making Ubuntu the default OS on boot



By default, Wubi has Windows as the default OS. To change that, here is what I did:

1. Boot into Windows XP.

2. Go to Control Panel

3. Switch to Classic View

4. Choose: System -> Advanced -> Startup and Recovery

5. From "Default Operating System" drop-down list, choose "Ubuntu"

6. Click OK on all open dialog windows to close them

Ubuntu upgrade



From there, I followed my own instructions for updating the system and loading the various programs I use, starting with this blog post: http://kotowanandesu.blogspot.com/2009/08/updating-ubuntu.html. The system upgrade went smoothly.

Ruby development support



The next step was to install support for ruby development. I followed the steps I had documented previously in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-ruby.html.

Things had changed a bit since I installed 9.04. Here are the differences I encountered:

1. When I ran the command
sudo apt-get install libmysql-ruby libmysqlclient-dev
the virtual package name libmysqlclient-dev was resolved automatically and the correct components were installed without the need for any additional action on my part.

2. When I installed the ruby bindings for MySQL, the software installed correctly but the ri documentation was missing a lot of bits and pieces. I did not consider this a serious problem.

3. The menu option Applications -> Add/Remove Applications was replaced by Ubuntu Software Center. I discovered that when I started to type the name of an application into the search box, it auto-filled all matching names. This was faster than the old way of finding the packages I wanted.

No problems with the rest of the ruby-related stuff, except some of the ri docs for nokogiri were missing. For the scripts and aliases documented in the original blog post, I just copied the files from the Toshiba laptop.

Java development support



I followed the instructions I had documented earlier in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-java.html. Everything worked the same as the first time, with the following exceptions:

1. Eclipse Galileo was installed by default. No additional steps were needed on my part.

2. Previously, Eclipse installed with a default value for the classpath variable M2_REPO. This time, it had no default definition. In Eclipse, under Window -> Preferences -> Java -> Build Path -> Classpath Variables, I added M2_REPO to point to /home/dave/.m2.

3. This time, migrating my existing projects to the new instance of Ubuntu was easier, since I was copying them from another Ubuntu instance that was configured in the same way. The first time around, I copied project files from an OS X system that was configured a bit differently.

Tomcat install



I had some difficulty with the standard installation procedure the first time around, as described in this post: http://kotowanandesu.blogspot.com/2009/08/installing-tomcat.html. This time, I checked for updated documentation and found this information about installing Tomcat 6 on Ubuntu 9.10: https://help.ubuntu.com/9.10/serverguide/C/tomcat.html. Per that documentation, I ran the command
sudo apt-get install tomcat6
and the It Works! page came up fine.

ColdFusion install



I skipped the ColdFusion installation for the moment, since I wouldn't need it in the near future.

.NET support



As before (see http://kotowanandesu.blogspot.com/2009/08/installing-support-for-net.html), I entered the command
sudo apt-get install mono-devel


To install the IDE, used Ubuntu Software Center, and then found it under Applications -> Programming. Go figure. I didn't try the Hello, World! programs this time, because I'm confident in the package.

The NUnit and debugger installs went smoothly.

Git install



The git install went smoothly, as documented here: http://kotowanandesu.blogspot.com/2009/08/installing-git.html.

eXPlainPMT install



I skipped this install, since I've started using the Kanban approach rather than the iterative approach on personal development projects.

Firefox development add-ons



I skipped this, since I won't be using the Acer as my primary development platform.

...and the rest of it



All that remained was to copy files from the Toshiba to the Acer. Up and running!

Next: Flash player for Firefox libnspr4-dev dependency

Wednesday, August 12, 2009

Installing support for Ruby development

Previous: Updating Ubuntu.

Ruby


To install Ruby support:
sudo apt-get install ruby-full

Geany (an IDE)


Low let's get Geany, a rudimentary IDE I find handy for Ruby development.
sudo apt-get install geany

Gems (to install other Ruby packages)


This installation procedure is a little different from the usual apt-get thing.

1. Look on Ruby Forge and see what the latest version of Ruby Gems is: http://rubyforge.org/frs/?group_id=126. Hover over the .tgz filename to see the correct URL for the wget command.

2. The Ruby community does not recommend using apt-get to install Ruby Gems because Advanced Package Tool and gems may get out of sync about versions. The recommended way is to open a Terminal window and enter the following commands (in this case the version I found in step 1 was 1.3.4). Long lines are split for readability in Blogger. Use common sense.
cd ~
wget http://rubyforge.org/frs/download.php/57643/
rubygems-1.3.4.tgz
tar xzvf rubygems-1.3.4.tgz
cd rubygems-1.3.4
sudo ruby setup.rb
3. Note which executable was installed (a message appears near the end of the installation) and define a symlink to it. In this case it was version 1.8.
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
4. If the installation worked, the following command will display version information. In this case we want to see "1.3.4". By changing directories first I help myself believe the PATH was updated. I hear it's good to believe.
cd
gem -v

MySQL server


I use MySQL for Ruby on Rails development (and other things, too). To install:
sudo apt-get install mysql-server
Of course, you should set the MySQL root password to something other than "empty" when prompted. The installer starts mysqld. To be sure it worked, run
ps ax | grep mysql
and look for /var/run/mysqld/mysqld.pid.

After installation, you can stop and start MySQL through System -> Administration -> Services on the main menubar. Alternatively, you can start and stop MySQL from a Terminal window using the commands:
sudo /etc/init.d/mysql start
and
sudo /etc/init.d/mysql stop

MySQL GUI client


To install a gui client for MySQL, choose Applications -> Add/Remove Applications from the main menubar. If prompted to update the list of available packages, do so. Under Show, choose "All available applications". Select "MySQL Administrator" for a GUI client and "MySQL Query Browser" for a GUI tool for running queries. After the installer finishes, the two applications will appear under Applications -> Programming on the main menubar.

Ruby bindings for MySQL


Open a Terminal window and enter the following commands:
cd ~
sudo apt-get install libmysql-ruby libmysqlclient-dev
The package libmysqlclient-dev is a virtual package. When you run the command above, you will see an error message that shows the name of the real package. Substitute it in the command line and run it again. When I ran it, it showed libmysqlclient15-dev, so I ran the command this way:
sudo apt-get install libmysql-ruby libmysqlclient15-dev
Run this command to build it:
sudo gem install mysql

Rails


Use Gems to install Rails. Open a Terminal window and enter the following command
cd ~
sudo gem install rails
If the installation succeeded, the following command will display version information:
rails -v
Verify the installation by generating a trivial rails app:
cd ~
rails myrailsapp -d mysql
or, for sqlite3:
cd ~
rails myrailsapp
In myrailsapp/script, run the command:
./server
If all is well, a WEBrick server will start and will listen on port 3000 for HTTP requests. Try loading the following URL in a browser. You should see a welcome page.
http://localhost:3000

Testing tools


These are tools for test-driven-, behavior-driven-, and storytest-driven-development:
  • Autotest - continuous testing (part of ZenTest)
  • Cucumber - storytest tool
  • RCov - coverage tool
  • rspec - BDD tool
  • Webrat - browser simulator (used by Cucumber)

On Debian variants (like Ubuntu), you have to install a couple of libraries before installing Webrat. They are needed by Nokogiri, the XML libary used in Webrat.
sudo gem install ZenTest
sudo gem install rcov
sudo gem install rspec rspec-rails
sudo gem install cucumber
sudo apt-get install libxslt1-dev libxml2-dev
sudo gem install webrat

Some conveniences


I'm rather slow-witted, so I find it helpful to follow a few conventions even though I'm the only person working on my system or on my little side projects. I put my software development projects under a directory called /projects. I nearly always use Geany for Ruby on Rails development. I use rspec and Cucumber with these projects. So it's convenient to have a quick way to set up a new Ruby on Rails project in the usual directory that includes the elements I usually want and that creates a Geany project file. To that end, I created a shell script in ~/bin that sets these things up for me. The script newrailsapp looked like this as of the time I posted this information:
#!/bin/bash
if [ -z $1 ]; then
echo "usage: newrailsapp appname"
exit
fi
if [ -e $1 ]; then
echo "Can't create $1 because it already exists. Quitting."
exit
fi

# Create the rails app

rails -d mysql $1

# Generate rspec support for the app

cd $1
./script/generate rspec
./script/generate cucumber

# Create a geany project file for the app

echo "Creating geany project file $1.geany"
cd ..
echo "[indentation]" > $1.geany
echo "indent_width=4" >> $1.geany
echo "indent_type=1" >> $1.geany
echo "indent_hard_tab_width=8" >> $1.geany
echo "detect_indent=false" >> $1.geany
echo "indent_mode=2" >> $1.geany
echo " " >> $1.geany
echo "[project]" >> $1.geany
echo "name=$1" >> $1.geany
echo "base_path=/home/dave/projects/$1/" >> $1.geany
echo "make_in_base_path=false" >> $1.geany
echo " " >> $1.geany
echo "[files]" >> $1.geany
echo "current_page=-1" >> $1.geany
Also created these aliases in ~/.bash_aliases:
# Start Geany (IDE)
alias geany='geany &'
# Start and stop any Rails test server
alias server='script/server &'
alias server_stop='~/bin/server_stop'

The alias geany just starts Geany in the background. Saves a couple of keystrokes.

The purpose of server is to start a Webrick server for dev-testing a Rails app. It's meant to be run from a command line when you're in the appropriate project subdirectory. The server script looks like this:
#!/bin/bash
script/server &
The purpose of server_stop is to stop a Webrick server. It looks like this (with the usual caveat about long lines)
#!/bin/bash
kill -9 `ps -o pid,cmd --no-heading -p $(pgrep ruby)
| grep script/server | awk '{print $1}'`
The assumption is that there will only be one Webrick server running at a time. It's a safe assumption because all of this is set up for a single user environment.

Next: Installing support for Java development