Archive

Archive for the ‘mac’ Category

Installing Postgres8.3,8.4,9.0, Postgis1.3.3,1.4.1,2.0, pgRouting on OSX (updated)

February 15th, 2011 rupert No comments

(Updated):Postgres9.0.3 Postgis2.0svn

Before you go any further. Dump data before migrating and installing. Warning: Most of the packages listed below is installed by source.

1. Download the current postgres source. http://www.postgresql.org/ftp/source/

8.3:
$./configure --with-prefix=/usr/local/pgsql --with-python
 
8.4:
$./configure --prefix=/usr/local/pgsql --with-python
 
$make
$sudo make install

2. Don’t delete the postgres folder. You might need this later on for future compilations. See pgadmin3 admin pack below.

3. Add a postgres user from System Preferences > Accounts

4. Initialize the data directory

$mkdir /usr/local/pgsql/data
$chown postgres /usr/local/pgsql/data/
$su - postgres
$/usr/local/pgsql/bin/initdb -E utf8 -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.
The default text search configuration will be set to "english".

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

4. Install Geos , PROJ4, and Postgis

GEOS:

- install geos with the Kyngchaos installer

- installing by source

svn checkout http://svn.osgeo.org/geos/trunk trunk
cd trunk/
sh autogen.sh
./configure --prefix=/usr/local/geos --enable-python
make
make install
sudo make install

PROJ4:

svn co http://svn.osgeo.org/metacrs/proj/trunk/proj/ proj
cd proj
sh autogen.sh
./configure --prefix=/usr/local/proj4
make
sudo make install

POSTGIS:

8.3:
$./configure --with-pgsql=/usr/local/pgsql/bin/pg_config --with-geos=/usr/local/bin/geos-config
 
8.4 using Kyngchaos GEOS Framework:
$./configure --with-pgsql=/usr/local/pgsql/bin/pg_config --with-geosconfig=/Library/Frameworks/GEOS.framework/unix/bin/geos-config
 
9.0:using Kyngchaos GEOS + PROJ framework:(Update Feb 15, 2011)
./configure --with-pgsql=/usr/local/pgsql/bin/pg_config --with-geosconfig=/Library/Frameworks/GEOS.framework/unix/bin/geos-config --with-projdir=/Library/Frameworks/PROJ.framework/unix/ --with-gettext=/usr/local/share/gettext/
 
Note: libintl.h error. You need gettext
gcc -g -O2  -fno-common -DPIC  -Wall -Wmissing-prototypes  -DUSE_NLS -DLOCALEDIR=\"/usr/local/pgsql/share/locale\" -Iyes/include  -c shp2pgsql-core.c
In file included from shp2pgsql-core.c:15:
shp2pgsql-core.h:17:21: error: libintl.h: No such file or di
 
9.0.4: using src from GEOS + PROJ
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj4
 
$make
$sudo make install

If everthing is successful, you should see files in /usr/local/pgsql/share/contrib/.

cd /usr/local/pgsql/share/contrib/postgis-2.0
- legacy.sql
- postgis.sql
- postgis_upgrade_20_minor.sql
- spatial_ref_sys.sql
- uninstall_legacy.sql
- uninstall_postgis.sql

5. Starting postgres on boot. Download postgresstartup.tar.gz then extract to your /Library/StartupItems

6. Creating the database

createdb -E utf8 template_postgis
createlang plpgsql template_postgis
 
8.3:
psql -d template_postgis -f /usr/local/pgsql/share/lwpostgis.sql
psql -d template_postgis -f /usr/local/pgsql/share/spatial_ref_sys.sql
 
8.4:
psql -d template_postgis -f /usr/local/pgsql/share/contrib/postgis.sql 
psql -d template_postgis -f /usr/local/pgsql/share/contrib/spatial_ref_sys.sql
 
9.0 + postgis2.0:
psql -d template_postgis -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql 
psql -d template_postgis -f /usr/local/pgsql/share/contrib/postgis-2.0/spatial_ref_sys.sql

7. Install and download pgAdmin3 for MacOS X

http://www.postgresql.org/ftp/pgadmin3/release/

Update Feb 15, 2011: Use pgadmin1.12 to connect with postgres9. Other versions (1.8.4, 1.6.3 don’t work)

8. Startup pgadmin3. You will notice there is a window stating…

Server instrumentation
The server lacks instrumentation functions.
pgAdmin III uses some support functions that are not available by default in all PostgreSQL versions. These enable some tasks that make life easier when dealing with log files and configuration files.

9. Compile the adminpack. Go to $postgresql_install_directory/contrib/adminpack

$ make
gcc -no-cpp-precomp -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv  -bundle -multiply_defined suppress  adminpack.o  -L../../src/port -bundle_loader ../../src/backend/postgres  -o libadminpack.0.0.so
rm -f libadminpack.0.so
ln -s libadminpack.0.0.so libadminpack.0.so
rm -f libadminpack.so
ln -s libadminpack.0.0.so libadminpack.so
 
rupert:adminpack rupert$ sudo make install
Password:
mkdir /usr/local/pgsql/share/contrib
/bin/sh ../../config/install-sh -c -m 644 ./uninstall_adminpack.sql '/usr/local/pgsql/share/contrib'
/bin/sh ../../config/install-sh -c -m 644 adminpack.sql '/usr/local/pgsql/share/contrib'
/bin/sh ../../config/install-sh -c -m 755  libadminpack.0.0.so '/usr/local/pgsql/lib/adminpack.so'

10. Load the adminpack.sql into your maintenance and template database

$ psql -U postgres -d postgres -f /usr/local/pgsql/share/contrib/adminpack.sql 
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
...

11. Disconnect and Reconnect from pgAdmin3. You shouldn’t see the window again.

Continue only if you want pgRouting

12. Essentially we would need Boost Graph Library (BGL) a.k.a boost, Genetic Algorithm Utility Library (or, GAUL for short), and GEOS (which we installed earlier when we installed postgis).

13. The easiest way to install boost is using MacPorts.

$ sudo port install boost-jam
--->  Fetching boost-jam
--->  Attempting to fetch boost-jam-3.1.16.tgz from http://downloads.sourceforge.net/boost
--->  Verifying checksum(s) for boost-jam
--->  Extracting boost-jam
--->  Configuring boost-jam
--->  Building boost-jam
--->  Staging boost-jam into destroot
--->  Installing boost-jam 3.1.16_0
--->  Activating boost-jam 3.1.16_0
--->  Cleaning boost-jam
--->  Fetching gmake
--->  Attempting to fetch make-3.81.tar.bz2 from http://ftp.gnu.org/gnu/make
--->  Verifying checksum(s) for gmake
--->  Extracting gmake
--->  Configuring gmake
--->  Building gmake with target all
--->  Staging gmake into destroot
--->  Installing gmake 3.81_0
--->  Activating gmake 3.81_0
--->  Cleaning gmake
--->  Fetching boost
--->  Attempting to fetch boost_1_34_1.tar.bz2 from http://downloads.sourceforge.net/boost
...
$ sudo port install boost

Note: I encountered an error when I directly installed “sudo port install boost” on my first run. A quick workaround is to install boost-jam, then install boost afterwards. For more details:

Error: Target org.macports.build returned: shell command ” cd “/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_boost/work/boost_1_34_1″ && gmake all ” returned error 2 Command output: Makefile:2: *** missing separator. Stop.

14. You can check if boost was successfully installed by…

$ sudo port -v installed boost boost-jam
The following ports are currently installed:
  boost @1.34.1_3+darwin_9 (active)
  boost-jam @3.1.16_0 (active)

15. For GAUL, we don’t need slang base on http://pgrouting.postlbs.org/wiki/1.x/InstallationManual.

$ ./configure --enable-slang=no
$ make
$ make install

16. Ok, so this is the heartbreaker. I was able to get pass cmake on pgRouting on version 1.02 however, I received “undefined symbols” when linking the librouting.dylib

Linking CXX shared library ../../lib/librouting.dylib
Undefined symbols:
  "_errcode", referenced from:
      _shortest_path in dijkstra.o
      _shortest_path_astar in astar.o
      _shortest_path_shooting_star in shooting_star.o

For the complete error details, see pgrouting_problem.txt

17. Thanks to www.kyngchaos.com, we can install http://www.kyngchaos.com/files/software/unixport/pgRouting-1.0.1-4.dmg binary from http://www.kyngchaos.com/wiki/software:postgres

18. Now we can load the pgRouting functions to our template database

psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_core.sql 
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_core_wrappers.sql 
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_dd.sql
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_dd_wrappers.sql 
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_dd_tsp.sql
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_tsp.sql
psql -U postgres -d template_postgis -f /usr/local/pgsql/share/contrib/routing_tsp_wrappers.sql

References:

http://developer.apple.com/internet/opensource/postgres.html

http://www2.russbrooks.com:8080/2007/11/4/install-postgresql-on-mac-os-x-10-5-leopard

OSX CheatSheet

August 26th, 2009 rupert Comments off

1. iTerm – terminal with tabs.

2. MarsEdit- Blog Software. Im doing a local post on a local wordpress then copying and pasting to a remote wordpress.

3. Mac Shortcuts from http://www.danrodney.com/mac/index.html. Here’s a local post and another one.

4. How to create an ISO?

hdiutil makehybrid -o CS3v1.iso CS3

5. chmOX – CHM Viewer in OSX.

6. Git for OS X from google code.

7. Open a finder from terminal

open .

8. Keychain Access asking on passwordless ssh?

ssh-add
Enter passphrase: ******
ssh-add -l <to list your identities>
</to>

Credits goes to http://www.danrodney.com/mac/index.html

Picture 1.png

9. ln -s /Applications/TextMate.app/Contents/Resources/mate /usr/local/bin/mate Read more…

Categories: mac, osx Tags: ,

Mac Tip #1: Create ISO

August 7th, 2009 rupert No comments

This one has been lurking in my drafts folder… Might as well post it.

1. Create an iso

rupert:Desktop rupert$ hdiutil makehybrid -o CS3v1.iso CS3
Creating hybrid image...
..............................................................................
rupert:Desktop rupert$

2. Open Disk Utility -> Burn -> Select image from [1]

Categories: mac, osx Tags: ,

Firefox crashes on my Mac caused by Java Applet VM

December 17th, 2008 rupert No comments

After manually updating to Java MacOSX10.5 Update 2 two months ago, I noticed something weird with my Firefox. At first, I ignored it, “heh must be a screwed-up page Im trying to open…” But lately, I noticed that most of the pages I am opening with Java applets crashes consistently. So here is the culprit, try to delete java caches if there are any…

Trying to figure out which version of the java applet being used by FF
Picture 1.png

Picture 2.png

Deleting the cache.. Go to
/Application/Utilities/Java/ and launch Java Preferences.app or you could seach for “java preferences” in spotlight.

Picture 3.png

If the problem still persist, I bet we can trim down which java versions to use…

Picture 4.png

Categories: mac Tags:

Rails Note #12: Oracle on Intel Mac

December 5th, 2008 rupert 1 comment

1. Read http://www.foliosus.com/2008/05/05/connecting-ruby-on-rails-to-oracle-on-an-intel-mac-in-leopard-take-2/

2. Install Oracle Instant Client on Mac.

a. Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
- instantclient-basic-macosx-10.2.0.4.0.zip (34,020,719 bytes)

b. *Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
instantclient-sdk-macosx-10.2.0.4.0.zip (603,493 bytes)

OR download the whole bundle (10.2.0.4.zip) with sqlplus installed from my installers.

3. Put this on your sudo vim ~/.bash_profile.

export ORACLE_HOME=/Library/Oracle/instantclient/10.2.0.4
export TNS_ADMIN=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME

4. Make a symbolic link

cd /Library/Oracle/instantclient/10.2.0.4
ln -s libclntsh.dylib.10.1 libclntsh.dylib

5. Go to /Library/Oracle/instantclient/10.2.0.4 and edit tnsnames.ora. Point the Oracle SID to the IP where you installed Oracle.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.155)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )
 
 
ORCL_2_11 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.11)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )   
  )

6. Install the oracle-adapter for rails

sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org

7. In your database.yml file

development:
  adapter: oracle
  database: orcl
  username: youzhu_mobile_dev
  password: your_password

or browse the contents of a sample rails project youzhumobile.tar.gz

8. If you ever encounter an encoding problem, then we need to set the NLS_LANG environment variable before running script/server.

# export NLS_LANG=American_America.UTF8
# script/server

or I prefer setting it in the environment.rb

Rails::Initializer.run do |config|
  ENV['NLS_LANG']='American_America.UTF8'
  # Settings in config/environments/* take precedence over those specified here.

Note: If you don’t know your database encoding, then read this post.

Categories: mac, oracle, osx, rails, ruby Tags: , , ,