Category Archives: Apple

Reinstall (bless) rEFInd after Mac OS X update

If you are using Mac OS X 10.11 or later boot into recovery mode (command+R while booting) and in the terminal disable SIP:

$ csrutil disable

Restart and then check in what partition is EFI installed:

$ diskutil list | grep EFI
   1:   EFI EFI      209.7 MB   disk0s1


$ sudo mkdir /Volumes/EFI
$ sudo mount -t msdos /dev/disk0s1 /Volumes/EFI
$ sudo bless --mount /Volumes/EFI --setBoot --file /Volumes/EFI/efi/refind/refind_x64.efi --shortform
$ sudo diskutil unmount /Volumes/EFI

Enable SIP again in the recovery mode if needed:

$ csrutil enable

Install Android SDK and Tools with Eclipse in Ubuntu, Mac OS X and Windows

Here I’ll explain the process to install Android SDK and Tools. There are 4 things you have to install in order to develop Android applications:

  • Android SDK
  • Eclipse
  • Android Development Tools plugins for Eclipse (ADT)
  • Android Virtual Device (ADV)

Android SDK

You can download the latest version of the Android SDK for your OS at the official Android SDK web. Latest versions at the time of this writing are those:

Ubuntu android-sdk_r24.4.1-linux.tgz
Mac OS X

Once downloaded uncompress it anywhere you like in your hard drive. It can be for example in your users home folder (/home/username/android-sdk-linux for Ubuntu, /Users/username/Applications/android-sdk-macosx for Mac OS X, C:\Documents and Settings\username\android-sdk-windows for Windows XP, C:\Users\username\android-sdk-windows for Windows Vista/7/8/10) or beside other applications (/usr/lib/android-sdk-linux for Ubuntu, /Applications/android-sdk-macosx for Mac OS X, C:\Program Files\android-sdk-windows for Windows).

Be sure you have configured the JAVA_HOME, ANDROID_HOME and PATH environment variables:

In Linux edit the ~/.bashrc file:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/javac::")
export ANDROID_HOME=~/android-sdk-linux
export PATH=$PATH:~/android-sdk-linux/tools

For Mac OS X you should edit the ~/.bash_profile file:

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=~/Applications/android-sdk-macosx
export PATH=$PATH:~/Applications/android-sdk-macosx/tools


For Eclipse installation just go to, download it and install it.

Android Development Tools

Open Eclipse and go to “Help→Install New Software”, click “Add…” and enter “ADT Plugin” for “Name” and “” for “Location”.



Select that repository in “Work with:”, choose all the packages and proceed the installation. Click OK if you see a message saying that unsigned content is being installed . Once installed you have to restart Eclipse.

After the restart, Eclipse will ask you to configure the Android SDK location. Click “Open Preferences”, select “Use existing SDKs” and fill “Existing Location” with the path you used to decompress Android SDK. If you don’t configure it now you can configure it anytime in the Eclipse preferences under the Android options.


After configuring the Android SDK location path you will be asked to install SDK Platform Tools. Click “Open SDK Manager” (or select “Window->Android SDK Manager”), select all the packages inside “Tools” and the version of Android of your choice (I used 4.2) and click “Install X packages…”. Don’t worry if you see “Stopping ADB server failed (code -1).” in the log messages, it’s OK.

Android Virtual Device

Now that everything is installed you have to create an Android Virtual Device (AVD) so you can use the emulator. Open the Java perspective (Window->Open Perspective->Java or click the icon with the yellow plus sign at the top right of the IDE and select Java). You will see 2 new icons with the Android symbol in the tools bar. Click the one on the right that looks like a phone (the other one opens the Android SDK Manager), click “New…” and give your Android Virtual Device a name, a device type, a target, etc. If you can’t select a target just restart Eclipse so it can load the newly installed SDK Platform Tools.

In Ubuntu for 64 bit systems you can get this error when creating an AVD:

Error: Failed to create the SD card.
Error: Failed to create sdcard in the AVD folder.

To solve it install the ia32-libs libraries ( Beware that they are about 260MB:

sudo apt-get install ia32-libs

Your first Android Application

Now you are ready to create your first Android application. Create a new “Android Application Project” with all the default options, just fill a “Application Name” like “Hello World”. The default option uses a “BlankActivity” with a template that needs the the Adroid Support library. It will ask you to install it and is as simple as clicking the “Install/Upgrade” button showed in that dialog window.

And there you have a fresh new “Hello Word” Android application. If you make the mistake of clicking the “Run” button you will get an error like this:

Error in an XML file: aborting build

That’s because by default the opened file after creating this “Hello World” project is “activity_main.xml”. You can also notice that a new file called “activity_main.out.xml” has been created, and it even is marked with errors. Delete that newly created file and open the “” file under “src” folder. Now you can click the “Run” button. Select “Android Application” in the “Run As” dialog window.

I had a problem in Mac OS X Lion after running the emulator several times. When I tried to run the application the emulator crashed every time. Searching on the Internet I found this page where it explains that if you run the emulator in a secondary monitor and close it while in that monitor, a value of the X position of the window is stored and next time that value is bigger that the first monitors resolution and chashes. Deleting the emulator-user.ini file from the /Users/username/.android/avd/device_name folder (executing open /Users/username/.android/avd/device_name from a terminal window) and running the emulator again solved the problem.

As a hint I always deselect “Project->Build Automatically” option because I prefer to build the code manually pressing Control+B or Command+B.


Install PHP 7.0 in Mac OS X with MacPorts

I’ve used this process to install PHP 7.0 with MacPorts along side with PHP 5.6.

First make sure Mac OS X included Apache server is stopped:

$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Install PHP7 and some of its modules (full list here):

$ sudo port install php70
$ sudo port install php70-apache2handler php70-cgi php70-gd php70-curl php70-intl php70-iconv php70-gettext php70-mbstring php70-imap php70-mcrypt php70-xmlrpc php70-mysql php70-openssl php70-sockets php70-zip php70-tidy php70-opcache php70-xsl php70-sqlite

Create the base php.ini file from the development example:

$ sudo cp /opt/local/etc/php70/php.ini-development /opt/local/etc/php70/php.ini

Find current timezone, add a backslash in between and put it in php.ini:

$ TIMEZONE=`sudo systemsetup -gettimezone | awk '{ print $3 }'`
$ TIMEZONE=$(printf "%s\n" "$TIMEZONE" | sed 's/[][\.*^$/]/\\&/g')
$ sudo sed -i.bak "s/;date.timezone =/date.timezone = \"${TIMEZONE}\"/g" /opt/local/etc/php70/php.ini

Update MySQL sockets if you are using it:

$ sudo sed -i.bak "s#pdo_mysql\.default_socket.*#pdo_mysql\.default_socket=`/opt/local/bin/mysql_config --socket`#" /opt/local/etc/php70/php.ini
$ sudo sed -i.bak "s#mysqli\.default_socket.*#mysqli\.default_socket=`/opt/local/bin/mysql_config --socket`#" /opt/local/etc/php70/php.ini

Now with this command you’ll see the installed PHP versions:

$ sudo port select --list php
Available versions for php:
	php56 (active)

Select php70 as the active PHP version:

$ sudo port select php php70
Selecting 'php70' for 'php' succeeded. 'php70' is now active.

Enable PHP 7 in Apache:

$ cd /opt/local/apache2/modules
$ sudo /opt/local/apache2/bin/apxs -a -e -n php7

Restart Apache:

$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart

You can check in the console the php version:

$ php -v
PHP 7.0.0 (cli) (built: Dec 12 2015 11:18:35) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

If the current version is not 7.0 make sure that /opt/local/bin is defined before /usr/bin in the PATH variable:

$ echo $PATH

Also check that /opt/local/bin/php is pointing to /opt/local/bin/php70:

$ ls -l /opt/local/bin/php
lrwxr-xr-x  1 root  admin    20B Dec  5 23:25 /opt/local/bin/php -> /opt/local/bin/php70

If running phpinfo(); doesn’t show the 7.0 version check that only the module for 7.0 is loaded in /opt/local/apache2/conf/httpd.conf:

#LoadModule php5_module        modules/
LoadModule php7_module        modules/


Fix “avrdude: stk500_recv(): programmer is not responding” in Mac OS X Mavericks 10.9 – Arduino

If you get this error while trying to upload an sketch with Arduino IDE in Mac OS X Mavericks 10.9:

avrdude: stk500_recv(): programmer is not responding

The first thing you should be sure is that you have selected a correct USB port (Tools -> Port, which should be something like /dev/cu.usbserial). If even that you are unable to upload an sketch try this process.

– Disable the Apple FTDI USB driver:

$ cd /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns
$ sudo mv AppleUSBFTDI.kext AppleUSBFTDI.kext.disabled

– Restart Mac OS X.
– Install the original FTDI driver from here:



Fix “Communications link failure” in Java applications with MySQL

You may have problems connecting to MySQL from Java applications using Connector/J (the Java connector for MySQL) after upgrading/migrating MacPorts to a newer version. It happened to me after updating Mac OS X to El Capitan and upgrading MacPorts to work with it. Everything worked fine with phpMyAdmin and other applications using PHP but Java applications wouldn’t connect:

Exception in thread "main" java.lang.IllegalStateException: Cannot connect the database!
	at Main.main(
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	at com.mysql.jdbc.Util.handleNewInstance(
	at com.mysql.jdbc.SQLError.createCommunicationsException(
	at com.mysql.jdbc.MysqlIO.(
	at com.mysql.jdbc.ConnectionImpl.coreConnect(
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(
	at com.mysql.jdbc.ConnectionImpl.createNewIO(
	at com.mysql.jdbc.ConnectionImpl.(
	at com.mysql.jdbc.JDBC4Connection.(
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	at com.mysql.jdbc.Util.handleNewInstance(
	at com.mysql.jdbc.ConnectionImpl.getInstance(
	at com.mysql.jdbc.NonRegisteringDriver.connect(
	at java.sql.DriverManager.getConnection(
	at java.sql.DriverManager.getConnection(
	at Main.main(
Caused by: Connection refused
	at Method)
	at com.mysql.jdbc.StandardSocketFactory.connect(
	at com.mysql.jdbc.MysqlIO.(
	... 15 more

You can test a simple connection in Java with this code in a file named

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/database_name";
        String username = "username";
        String password = "password";

        System.out.println("Connecting database...");

        try (Connection connection = DriverManager.getConnection(url, username, password)) {
            System.out.println("Database connected!");
        } catch (SQLException e) {
            throw new IllegalStateException("Cannot connect the database!", e);

And running it like this (you’ll have to download the Java MySQL connector and place it in the same path with the .java file):

$ javac
$ java -cp .:./mysql-connector-java-5.1.37-bin.jar Main

I could connect to MySQL databases from the console using mysql so my server was running. I checked the usual configurations in my.cnf and didn’t see nothing wrong. The binding address was correct (it was so connections from any IP could be done) and the socket file was also fine.

# Use default MacPorts settings
!include /opt/local/etc/mysql55/macports-default.cnf

port            = 3306
socket          = /opt/local/var/run/mysql55/mysqld.sock

port            = 3306
socket          = /opt/local/var/run/mysql55/mysqld.sock
bind-address    =
max_allowed_packet = 256M

And then I saw it. Look at the include line. The problem was that the /opt/local/etc/mysql55/macports-default.cnf file in that include had been rewritten when MacPorts was updated and it had the skip-networking option enabled.


So the problem was solved by just commenting it out and restarting MySQL server.