Twitter Updates

Showing posts with label Darwin Ports. Show all posts
Showing posts with label Darwin Ports. Show all posts

Tuesday, 15 December 2009

Sinatra First Blog attempt

After getting Xcode for Snow leopard correctly installed and restarting. The basic sinatra works correctly.

hi.rb
----
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end

Command line:
$ gem install sinatra
$ ruby hi.rb

Then checkout 127.0.0.1:4567.

Turning it an almost blog, with some erb and an sqlite 3 database.
Assuming you have macports installed you can do (or look up installing sqlite3):
$ sudo port install sqlite3
cd Sinatra_dir
sqlite3 blog
#you are now in the sqlite command prompt
sqlite> create table posts (title text, body text );
sqlite> insert into posts values('title1','Very long article');
sqlite> insert into posts values('Sinatra Blog Post','text text text text text');

hi.rb
----
require 'rubygems'
require 'sinatra'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:dbfile => 'blog.db'
)
class Post < ActiveRecord::Base
end

get '/news/?' do
@posts = Post.all()
erb :index
end


Now create ./views/index.erb
----
HelloWorld!

<% for post in @posts %>
< h 1><%= post.title %>< / h 1>
< p ><%= post.body%>< / p>
<% end %>


$ ruby hi.rb and goto 127.0.0.1:4567.
If all goes well you should see some thing like this:

Monday, 14 December 2009

whereis alternative to which

whereis is a nice alternative to which for finding the location of unix programs.

$ which ruby
> /usr/local/bin/ruby

$ whereis ruby
> /usr/bin/ruby

Problems with Snow Leopard and Ruby Gems

UPDATE 2 (update 1 at the bottom with some extra ruby version info)
When you install Xcode make sure is is the latest version. I must have at some point installed the old Leopard version. then when things did not work reinstalled that same old version. I found xcode321_10m2003 in my downloads folder not the older one I had put in a software folder. You may still need to update Ruby to a new version.

Make sure you have the latest Xcode.


I have been trying to get the very simple Sinatra (a light ruby on Rails) setup working following the verysimple instructions on http://www.sinatrarb.com/

Make a file called hi.rb with this inside:
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end

Then run these commands:
$ gems install sinatra
$ ruby hi.rb


They fail with:
hi.rb:2:in `require': no such file to load -- rubygems (LoadError)
from hi.rb:2

After removing the require 'rubygems', is it actually still required ?
hi.rb:3:in `require': no such file to load -- sinatra (LoadError)
from hi.rb:3

To fix this I ran through the instructions at http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/

Their instructions worked well until the mysql gem which I do not require at the moment but do like to get my set up the same as the tutorial. I found the following line on stackoverflow.
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysqlplus


Finally got the basic sinatra working by calling:
$ /usr/local/bin/ruby hi.rb
Even though which ruby returns /usr/local/bin/ruby, so why does ruby hi.rb not just work!

What is going on just thought I would check to see if calling the other ruby breaks it, but it works fine.
$ /usr/bin/ruby hi.rb


UPDATE
For completeness and to answer Spyro7's Question:
$ /usr/local/bin/ruby -v
> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

$ /usr/bin/ruby -v
> ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

Monday, 2 November 2009

mac ports since OS X Snow Leopard upgrade

Since upgrading to Snow Leopard I have noticed that Mac Ports (Previously called Darwin Ports) started giving me lots of errors. So I manually downloaded and installed the latest version, from here.

I then had to run through the insructions here [1] to clean every thing up:
[1] http://trac.macports.org/wiki/Migration

$ port installed > myports.txt
$ sudo port clean all
$ sudo port -f uninstall installed


The look through myports.txt and install any you need.

$ sudo port install fping scite

Wednesday, 16 September 2009

New NTFS driver for Mac OS X

There is a recent driver out for Read/Write support of NTFS drives under Mac OS X.
Download

There is now an NTFS-3G item in the system preferences. I would recommending unchecking the "File system Caching enabling". This with disk caching the mutliple read writes to the same data can be much faster but can corrupt the disk if the buffer is not flushed before removal. Ejecting or unmounting the disc is the way you tell the computer you want to flush the buffers and remove the disk. BUT I occasionally forget to do this for external discs and I dont want to lose all my data. On the plus side I do not work (edit data) on external discs just transfer/Archive data or play/read files so I do not see any performance loss.

The new driver also has a force button for when windows did not shut it disc down correctly. So you can force OS X to load the disc any way, this was a real pain in my old version of the driver.

Release Notes Updates can be found here:
http://macntfs-3g.blogspot.com/

Sunday, 19 July 2009

OSX eat my GNU

Trying to setup snapback2 bbackup software but started running into issues because the os x commands are based on the BSD variants not the more standard GNU versions used on most Unix's and Linux's.

Tried some manual installs but eventually after hitting a few dead ends found the package in port (mac ports formerly darwin ports).

1) Assuming Mac Ports is already installed (if not do that first, to tired to give instructions for that)
2) $ sudo port install coreutils
NB: since os x 10.5 sudo only works if you have a password set.
3) Get that pesky BSD cp out the way
$ sudo mv /bin/cp /bin/cp-osx
4) link to the new shiny GNU
$ ln -s /opt/local/bin/gcp /bin/cp

5) test old version
$ cp-osx --version
>/bin/cp-osx: illegal option -- -
>usage: cp [-R [-H | -L | -P]] [-fi | -n] [-pvX] source_file target_file
>cp [-R [-H | -L | -P]] [-fi | -n] [-pvX] source_file ... target_directory

Note The excellent handling when requesting the version!

6) Now the new version:
$cp --version
>cp (GNU coreutils) 7.4
>Copyright (C) 2009 Free Software Foundation, Inc.
>License GPLv3+: GNU GPL version 3 or later .
>This is free software: you are free to change and redistribute it.
>There is NO WARRANTY, to the extent permitted by law.
>
>Written by Torbjörn Granlund, David MacKenzie, and Jim Meyering.

This can be repeated for any other GNU commands you would like to map from /opt/local/bin/ to /bin. Most are prepend with g but if it is a 3rd party script that you are trying to get working it is often easier to make the default the gnu version.

Sunday, 30 November 2008

Mac OS X 10.5 Clean Install

When I upgraded my macbook harddrive I took the opportunity to do a clean install of OS X and to figure out which programs I really needed.

After installing the harddrive, power up and insert the Leopard disc-01 you will need to press C to boot from CD. The BIOS might have missed this when you were inserting the disc so may need to power cycle (switch on and off again). Other boot options

The install was pretty straigh forward but unlike every other OS installer it does not bring up the disk partition and formatting box by default so you have to go looking for the disk utility in the top right menu, very annoying!

after an hour it asks for the second disc, which it fails to recognise the first time. Cant remember if I had eject and insert the disc several times ot power cycle but it then accepted the disc and an hour later the fresh install of OS X was complete.

I then installed al the programs I was going to need.

Firefox 3.0.3 [Free]
Quicksilver 3815 [Free]
Xcode 3.1.1 [Free with apple developer registraion also free]
Macports 1.6 [Free]
istat pro 4.71 Dashboard [Free]
VLC 0.95-Intel - Media Player with most codecs built-in [Free]
Max 0.8.1 - Audio conversion [Free]
Lightroom 2 [NOT Free]
Photoshop CS3 [NOT Free]
Handbrake - Video encoder [Free]
Smultron - text editor [Free]
Visual Hub - Now called FilmRedux [Now Free]
Super Duper - Clone bootable drives [Used Free version]
Sound Pref - stop OS X boot up sound, previous post [Free]

After the installation:
Restore my firefox settings, including bookmarks and passwords

Create a user bin folder, for scripts
$mkdir ~/bin
Copy from backup all my scripts in to this folder.
Configure the Terminal and X11 setting and then restore my .bashrc & .bash_profile

Set up scripts to mount my samba shares
Set Desktop Icon size
Set Background Image and screen savers

Sunday, 16 November 2008

Install mysql on Mac OS X 10.5

I have trying out some ruby on rails which requires a database, the most common for rails is mysql.

Itried the mac ports install
$sudo port -d selfupdate
$port search mysql
$sudo port install mysql5

but that did not seem to work ie '$which mysql' returns no results

Note: checking out the contents of /opt/local/bin I notice that mysql5 and mysqladmin5 are there. so using these program names it might have all been working!

Apple have this guide
http://developer.apple.com/internet/opensource/osdb.html

The following way seemed to work for me:
Download the Mac OS X Package from http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg. Requires a free registration but led me to this link in the end

http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67-osx10.5-x86_64.dmg/from/http://mirrors.ukfast.co.uk/sites/ftp.mysql.com/

just download mount the .dmg (by double clicking on it) then install both .pkg inside (by double clicking on it).

dont forget to add this to your path
$vim ~/.bashrc
Paste in the follwoing
#Add path for mysql package
export PATH=$PATH:/usr/local/mysql/bin/

now '$which mysql' and '$which mysqladmin' should return results

NB: I had to reboot to get the mysql demons (the server) to start, but I am sure there is a quicker way of starting the server up after the first install.

Sunday, 17 August 2008

Linux, Mac Os X and Windows Portable Filesystem

[Update] Newer easier to use MAC NTFS driver post [/Update]

Portable file systems between all 3 big OS, Linux, Mac OS X and Windows.

Fat32 is compatible with all three but is very inefficient when dealing with larger disks (500GB+).

Unfortunately the most compatible seems to be Windows NTFS. Using FUSE and NTFS-3g on Linux and MAC we can have Read/Write access, I do not think that the Journaling is used though.

Mac OS X guide at http://ntfs-3g.darwinports.com/
Basically install mac ports
then $ sudo port install ntfs-3g

NB: when switching on external drives they will try to automount. if the safe device removal is not used the NTFS disk is labeld as an unclean mount. (Even if the windows option is set to write directly to the driver, and not use a cache to improve performance)

The dialog box that displays this warning does not list the correct command to fix it it should be replaced with something like :
$ /usr/local/bin/ntfs-3g /dev/rdisk2s1 /Volumes/Terra02 -o force

Sunday, 27 July 2008

Darwin Ports useful commands

To update the ports
sudo port -d selfupdate

To search for and install a port, example program is fping
port search fping
sudo port install fping

More information can be found at
http://trac.macports.org/wiki/UsingMacPortsQuickStart

[Edit 19/07/2009]
This page looks like a very good resource on port commands:
http://guide.macports.org/#using.port

Wednesday, 4 June 2008

My favourite terminal torrent client

I have been looking for a nicer terminal bit torrent client than bit tornado for a while and came across rtorrent. It has its own wikipedia page. I have found this torrent client to be much faster than the official version.

It is easily installed on Debian and Ubuntu systems with
$sudo apt-get install rtorrent

NB: if $apt-cache search rtorrent does not return any results you may need to add some thing to your sources list.

On OS X it is available once you have installed and setup Darwin ports.
$sudo port install rtorrent
Good tutorial here for getting it running

Saturday, 31 May 2008

Darwin Ports

I recently found out about the Darwin Ports. It is built on the BSD package management system and lets you easily install unix programs that have been ported to os x. The package management part of it handles the dependencies for you. You do need to install Xcode first though.

http://darwinports.com/

Once downloaded you need to add the darwin ports binaries folder to the search path. from the terminal run (or manually added the path to the .bashrc)
$echo 'export PATH=$PATH:/opt/local/bin' >> ~/.bashrc
$echo 'export PATH=$PATH:/opt/local/sbin' >> ~/.bashrc