Using homebrew with multiple users on a single machine

I a big fan of homebrew. I have been using it for a while now and i am like a lot. But i recent hit a big headache with permission issue with another account on my Mac.

I installed homebrew using a previous user account, but this proved to be very unforgiving to install software from the new user account.

brew install redis
Error: Cannot write to /usr/local/Cellar

The following steps will enable the new user and/or other users to install software with homebrew. BTW thanks for Geoff Low (glow) for helping out.

Firstly set the umask for the user. (inside the .bashrc or .profile or .bash_profile)

umask 0002 # grant write permission to group

For more on umask.

then recursively grant group write permission to /usr/local directory:

sudo chmod -R g+w /usr/local/

then also change recursively /usr/local group to staff:

sudo chgrp -R staff /usr/local

Alright thats it you should be good to go now with the new user account installing software with homebrew.

Be sure to run and follow any further instructions:

brew doctor

NB: It is worthy to note that homebrew by design requires that in your user profile file (i.e. .bashrc or .profile or .bash_profile), that your set /usr/local/bin ahead of /usr/bin to avoid clashes with system software tools that may exist in other paths on your machine. it is important that you override the system paths to use homebrew installations as default.

Setting Up SBT (Simple Build Tool) on Unix For Building Scala Based Project.

One of the problems that plagued the Java development space prior to the advent of tools like ANT and Maven, was the lack of automated build tools.

Previously, Java developers had to either write thier own build script which knew no unformity at all or do javac *.java (did this really work.. hmm).

But today setting up a Java project is gradually becoming a trivial task especially with tools like Maven and SBT.

SBT is a build tool for Scala based project. SBT integrates very well with Maven.

The feature of SBT, i like is the continuous compilation (~compile) this is very useful especially when testing and/or debugging.

Kudos to the hands behind SBT and Maciej Matyjas for recommending SBT to me..  you guys rock. period !

Alright, lets delve in and set up an SBT build environment.

Firstly, you need to download the latest jar of SBT here

Next create the bin folder and move the SBT jar to the bin folder.

mkdir ~/bin
mv ~/Downloads/sbt-launcher-0.7.4.jar ~/bin

Next create the SBT file.

echo "java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar \`dirname \$0\`/sbt-launcher-0.7.4.jar \"\$@\"" | sudo tee ~/bin/sbt

I prefer this way of using “dirname” rather that using a relative or absolute path to the SBT jar file.

After this is done you may need to  change the read write mode for the SBT file.

chmod u+x ~/bin/sbt

This allows you to launch SBT file to run or execute.

Finally, set environment path for SBT, this file name varies across flavours of Unix. I use a Mac OSX 10. 6 and i use .profile or .bash_profile to set my environment path.

For Debian this is .bashrc. Find out the file for setting environment variables for your flavour of Unix.

emacs .profile                              #(or nano .profile or any editor of your choice.. only have it in mind that these type of files are hidden system files)
export PATH=$PATH:~/bin                     #(copy and paste this in to .profile)
source .profile

This allows you to launch SBT from any directory by typing sbt at the terminal.

Type sbt on terminal to enjoy the it’s euphoria.

For more on SBT here

Installing Scala on Mac OS X via Darwinports

Following the brilliant talks and much encouragement i received about the Scala Language, i finally woke up with this objective of delving into Scala.

The installation steps i found on the internet were quite trivial and straight forward, but did not work on my MAC OS X laptop.

The one way that worked for me finally after several attempts was via the following steps (found here also).

1. Firstly i downloaded and installed the Darwinports installer and also type this command to update Darwin:

 sudo port -d selfupdate

2. After step one is completed, check if this directory path exist ” /opt/local/bin/portslocation/dports/scala ” on your system.


cd /opt/local/bin/portslocation/dports/scala

if the above directory path already exist on your system, skip step 3.

3. if  the above path is not in existence, type the following one line after another and hit return to create the folders:

sudo mkdir portslocation
cd portslocation
sudo mkdir dports
cd dports
sudo mkdir scala
cd scala

4.  Type the following and hit return:

sudo port install scala

this will officially install Scala for you.

5. Finally you might want to verify your Scala installation via the following commands:

sudo port location scala
man scala
apropos scala
which scala
locate scala

6. Hopefully Scala 2.8.0 will be out sometime in April 2010. Upgrading can be achieved with:

sudo port upgrade scala

Cheers.

Unix “PS” command

Today, i meet a senior colleague in the field of software named JOE WALNES.

While i was showing Joe what i had done earlier today with WICKET.

I was unable to run the my small WICKET app, because tomcat was still running, and i was unable to  shutdown the tomcat instance that i had earlier on started on my MAC Book.

He simply opened my eyes to the PS command on unix systems.

The PS command showes the unique id and related information of the currently running processes on the computer.

Since tomcat is java based and uses a bootstrap to run, he also exposed me to the “JPS” command.

This performs a similar function like the PS command, only selects processes that are java based.

This blog post i hope would be useful to someone out there and also serve as a reminder in case i need to come back to this in the future.

By issuing the PS command it generates a unique id for the system alone, so take note that the ID for processes vary from system to system, so when you apply the “kill” command remember to append the immediate ID of the process you want to shutdown.

"gem mysql install" problem on Mac OS X (Leopard)


 


I executed the db:migrate via netbeans GUI and it threw this error:

*******************************************************************

* config.breakpoint_server has been deprecated and has no effect. ********************************************************************

!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.

rake aborted!

no such file to load — mysql

And obviously, I went ahead to install the mysql gem
“gem mysql install”
and returned this error:

WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren’t both writable.
WARNING: You don’t have /Users/ikenna/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no

Gem files will remain installed in /Users/ikenna/.gem/ruby/1.8/gems/mysql-2.7 for inspection.
Results logged to /Users/ikenna/.gem/ruby/1.8/gems/mysql-2.7/gem_make.out

But after googling and trying out so many versions of bash commands, Finally the solution that worked for me came…. thanks to this guy “kevin.sylvestre” via the Railsforum.

He stated and i quote:

Before installing the gem you first need the MySQL binaries (http://dev.mysql.com/downloads/mysql/5.1.html). For Mac OS X use the Mac OS X 10.5 (package format) (x86). Then:

>

sudo env ARCHFLAGS=”-arch i386″ gem install mysql — \
–with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib \
–with-mysql-include=/usr/local/mysql/include>

 

This solution worked very well for me and i hope this could help someone else… hopefully…

Cheers.

2002 – Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’

Today, i stopped being a fan of MAMP for integrating PHP Apache and MYSQL, and i decided to setup Apache, MYSQL and PHP stack on my MAC OS X 10.5.7 (leopard) the good old way…


But, i encountered this error: 2002 – Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2).

Wow… i then discovered funny enough, that MYSQL instance was running perfectly and i was able to connect MYSQL
via the MYSQL Admin GUI tool.

I made a lucky guess asserting, that the PHP config file may be missing some info, Hmmm…

Well the solution goes as follows:

I searched for “mysql.lock” and i discovered that the MYSQL Socket file was located in “/tmp/mysql.lock.

Also, in the my PHP.ini file the value formysql.default_socket” was entirely empty “”.

ehhhh… Run this command in Terminal to view hidden files “defaults write com.apple.finder AppleShowAllFiles TRUE” and then followed by “killall Finder”.

Then Go to “private/etc/PHP.ini”. (note: private is a hidden folder).

If prior to this, in “private/etc/ “folder, the PHP.ini file does not exist copy and paste it there first.

Now open the PHP.ini file with say BBedit or TextWrangler.

Use command + F to find “mysql.default_socket” and paste “/tmp/mysql.sock” as it’s new value.

Finally restart your Apache web server with Terminal using “sudo apachectl graceful”.

After restart, PHP will be able to make connection calls to MYSQL with no further a do or hassle.

Configuring Postfix on Mac (Local SMTP)

During one of my hack trips.. i was required to use postfix capability. Alright i am a newbie to the Unix environment but i learnt this Hack from sniffing around with some luck on my side..

Well i decided to share my thoughts:

i tried a lot of things to try make this work, but the follow i think are the relevant steps.

Firstly; I did this:

sudo mate /System/Library/LaunchDaemons/org.postfix.master.plist

and then added this lines of xml code, add following line before the closing tag:
<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>

then after start service with

sudo launchctl
launchd% start org.postfix.master
or simply run
sudo postfix start

Another thing is editing the following files:
Edit the MAILSERVER=-NO- line in /etc/hostconfig. Change it to read MAILSERVER=-YES-. Save and exit the file.
Open up /etc/postfix/main.cf, and edit these lines to reflect your setup. These are examples from my setup; yours might be different.
LINE 67: myhostname = localhost
LINE 75: mydomain = localhost
LINE 91: myorigin = $mydomain
LINE 105: inet_interfaces = all
LINE 152: mydestination = $myhostname, localhost.$mydomain
LINE 239: mynetworks_style = subnet
LINE 253: mynetworks = 192.168.0.0/23, 127.0.0.0/8
Save your work, and exit the file.
Open up /etc/postfix/master.cf, and uncomment line 77 -- change #smtp inet n - n - - smtpd to smtp inet n - n - - smtpd. Save and exit the file.

Check that postfix SMTP mock is running:

telnet localhost 25