Setting up the Raspberry Pi for programming from Mac OS X

In this article I will explain how I set up my Raspberry Pi to be programmable from my macbook pro. I didn't want to use an external monitor & keyboard, nor did I want to connect my Pi to the router of my home network as this setup would not be very mobile. To achieve this, I made use of SSH and the mac's ability to share its internet with other computers. I will not use any GUI to do the programming, as I find that running a GUI on a small embedded computer like this is overkill. Instead I will do all the programming from the command line. A small example of how to do this is included here as well. This article was mainly written as a future reference for myself, but I hope it can be useful for others as well.

Step 1: Prepare the SD-card

First of all, you will need an SD-card with a bootable linux image. I recommend using the "Raspbian Wheezy" image, which is an optimized version of debian. It is downloadable from Instructions for putting the image on the card properly can be found on the eLinux website.

Preparing SD card

If this has succeeded, you can boot up your Raspberry Pi! For the initial boot we will need an external monitor & keyboard, so we can set everything up properly.

Step 2: Basic configurations

The easiest way to do the basic setup is by making use of the raspi-config tool, it should start up automatically on your first boot.

If it doesn't start automatically, you can also launch it with:
sudo raspi-config
I would recommend starting off by setting configure_keyboard and change_timezone. As we won't use any GUI for our programming, it is a good idea to set up memory_split so that the ARM gets 240MB of RAM and the VideoCore only 16MB as this will speed up things a lot. If you have a large SD-card (> 4G) you might want to consider using expand_rootfs to enable all this space. The downside of this is that backups of your SD image will be significantly larger.

The most important thing we had to do here, was to enable SSH. The more recent versions of raspbian have this enabled by default though.

If you have used configure_keyboard, you should run:

sudo setupcon
to avoid a massive delay in the boot process.

Step 3: Find out the Raspberry Pi's IP adres

At this point, we need our Pi connected to the internet. If you have a router close to your working environment, plugging it in there would be fine. If you don't however, it is very easy to use the "internet sharing" option on a mac to provide internet to your Raspberry Pi. On your mac, go to: "System Preferences > Sharing".

As you can see, I chose to share my macbook's wifi through the ethernet port. If I plug in my Raspberry there, it will have internet.

Now go back to the Raspberry Pi's monitor & keyboard. To be able to connect to the Pi through SSH, we need to know the IP adres it is using. To find it out, we enter the following command:
You should see something like "inet addr:".

Step 4: Connect to the Raspberry Pi from your mac

Now we know everything we need to know and everything is set up properly, we can disconnect the monitor & keyboard from our Pi (forever). To connect establish the SSH connection, go to the mac terminal and type (you should of course change the IP with the one you found earlier):

ssh -lpi

If it is the first time you connect to this device, you will probably see something like "The authenticity of the host can't be ... blabla". You can answer "yes" to this.

You will be prompted for the password now. If you did not change this in step 2, and you are using the recommended raspbian image, the password is "raspberry". Enter this, and you are now logged in to the Pi! You should see something like this:

Step 5: Setup a basic programming environment

You don't need much to programming from the command line in linux, but you do need a good text editor. I use vim. If this is the first time you work with vim, I recommend taking 10 minutes time to check out a good tutorial. To install vim on your raspberry pi, simply type:

sudo apt-get install vim

Because I think syntax highlighting and line numbering are essential programming tools, I want to enable these by default. You can do this by editing (or creating) the .vimrc file in your user directory. We'll do this using vim:

vim ~/.vimrc
Then add the following two lines:
syntax on
set number

Now it's time to test our tools! If you write a very simple "Hello World!"-program with vim, it should look like this:

If you name the file "main.cpp", you can compile it with:

g++ main.cpp -o HelloWorld
If you then run it with:
you can sit back, and enjoy the most simple program in the world!

If you're interested in doing some more advanced programming of your Raspberry Pi, check out my article on Low Level Programming of the Raspberry Pi.


I found your article about "Setting up the Raspberry Pi for programming from Mac OS X" very interesting, but I have not been able to connect by ethernet my "Raspberry Pi" with my "Mac Pro". It seems that the configuration to share an "Internet connection" is more complicated than what you've shown.
Can you help me?

My configuration :
- LAN with router and DHCP server (ADSL BOX)
- Mac Pro with "OS X Mountain Lion" and Wifi connection with DHCP client (192.168.0.xx)
- ethernet cross-over cable between "Mac pro" and "Raspberry Pi"

Can you be more specific about the problems you are having with my approach? I have checked this on another computer and it works just fine. Are you sure you are using the correct cables etc.? Thanks

Yes, the cable is OK!
When I connect it to the BOX/ADSL, I get an IP address automatically via DHCP:
When I connect it to the Mac, the ethernet connection on the Mac gives me the following IP address with the subnet mask, and, of course, I followed the "Step 3". But I don't get an IP address on the "Raspberry Pi"!
Below is a copy of the result of the command "ifconfig" (I masked the MAC address)
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
RX packets:90 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:11865 (11.5 KiB) TX bytes:7931 (7.7 KiB)

After I made a short-circuit on my raspberry pi, I had the same problem as you. I solved it by turning the "internet sharing" option on my mac off and on again. It worked instantly. Let me know if this works for you too. Sorry you had to wait so long for another reply from me. Maybe you have to connect your Raspberry Pi to the mac first, and then enable internet sharing?

Any way to get started with Pi without ever using an external monitor? All I have are laptops in my home, no external screens. Suggestions welcome :):)


Pieter-Jan, you must be from Holland. So am i, so will type in Dutch:

Ik heb problemen ervaren.

Ik ben nu bij stap 5. Ik wil VIM installeren op mijn Raspberry Pi door "sudo apt-get install vim" in te typen in de XL Terminal van de Raspberry. Als ik dat doe geeft de Raspberry aan wat hij wil installeren en vervolgens krijg ik de optie om door te gaan of te stoppen door "Y" of "N" in te typen. Als ik "Y" typ geeft ie aan dat pagina "404 not found" melding. Hier loop ik dus vast.

Ik heb evt. screenshots (foto's) gemaakt van de meldingen die ik je mogelijk kan mailen.

Je tutorial is duidelijk en ik waardeer het. Maar ik hoop dat je me verder kunt helpen.

Alvast bedankt!


I apologize! You're Belgian!

I finally fixed my previous problem, but now i have another one:

Its step 4. when it asks my password (which is still 'raspberry') in the terminal i can't type! So now im not able to enter the password! Please help!

Thanks in advance,


Hello, sorry for my late reply. If debian asks you for a password it will not show the characters you are typing. Just type the word and press enter. It should work.

Hello Pieter,
After hours of search, I am really glad to find your tutorial. Just what I'm trying to do.
I'm traveling, with a macbook Pro and a Raspberry in my luggage, trying to connect both of them without success through an ethernet cable. ( wifi Internet connection ).
… But I'm still having the same problem Ricardo Anaya told you, even after your advice of " turning the "internet sharing" option on your mac off and on again ". The IP address is still something like " with the subnet mask ".
The problem also is that I can't connect the Raspberry to another monitor to find out what it's IP is… is there a way to find it through the macbook Pro ? :/
Thank you for your help :) ! ®

Hello, does anyone know how I need to configure the Mac keyboard in the Raspberry PI configuration in order to use all keys e.g. to use square brackets, etc.?
Many thanks in advance, Tino

Hi! I searched for hours on this. Do you know if there is a way to now ssh to the pi via a computer on the wifi network (using the internet sharing)? I have my imac wired to the pi and it works fine with the same configuration as yours. I am wondering (and hoping) if I can cross the subnets, since the pi is in 192.168.2.x, and all other computers are in 192.168.1.x. Your help is greatly appreciated.

Very energetic article, I loved that bit.
Will there be a part 2?

It's actually a great and useful piece of info. I'm happy
that you simply shared this helpful information with us.
Please keep us informed like this. Thanks for sharing.

A nihe post, thanks from a big gaming lover.

When I originɑlly left ɑ commeոt I appear to hɑve cliϲκed on the -Notify me when new comments are aԁded- cheϲkbox aոd now evеry tіme a comment is added I receive 4 emails with the same comment.
Thеre has to be a means you can remove me from that serνice?
Thank you!

Thanks designed for sharing such a nice idea, article is pleasant, thats
why i have read it entirely

Add new comment