bashrc in Mac OS

If you are working with CUDA or OpenCV on Mac OS, you need to provide proper paths before you compile. And in some cases you need to give these paths every time you open a terminal. In Linux, there is bashrc file in which we can add all the paths. But in Mac OS, I could not find it. We need to create a profile and it loads every time we open a terminal.

To make your own profile, open the terminal and type

sudo vi /etc/bashrc

At the end of this file, add the following line

source ~/.bashrc

Now if you restart the terminal, you get a warning :

-bash: /Users/username/.bashrc: No such file or directory

Now create this file

vim .bashrc

Add whatever the paths you want into this file. For example, I would add

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr

Save the file.

Now restart the terminal. Whenever you start a terminal from now on all the settings in bashrc file are loaded.

Done and done! 🙂


Installing CUDA on Mac OS

CUDA is a parallel computing platform and programming model that enables dramatic increases in computing performance by harnessing the power of the graphics processing unit (GPU).

In this post, I will tell you how to get started with CUDA on Mac OS. To use CUDA on your system, you will need the following installed:

  1. CUDA-enabled GPU. A list of such GPUs is available here
  2. Mac OS X v. 10.5.6 or later (10.6.3 or later for 64-bit CUDA applications)
  3. The gcc compiler and toolchain installed using Xcode
  4. CUDA software (available at no cost from

Once you have verified that you have a supported NVIDIA processor and a supported version the Mac OS, you need to download the CUDA software. Download the following packages for the latest version of the Development Tools from the site above:

  1. CUDA Driver
  2. CUDA Toolkit
  3. GPU Computing SDK


  1. Install the CUDA Driver
    Install the CUDA driver package by executing the installer and following the on-screen prompts. This will install /Library/Framework/CUDA.framework and the UNIX-compatibility stub /usr/local/cuda/lib/libcuda.dylib that refers to it
  2. Install the CUDA Toolkit
    Install the CUDA Toolkit by executing the Toolkit installer package and following the on-screen prompts. The CUDA Toolkit supplements the CUDA Driver with compilers and additional libraries and header files that are installed into /usr/local/cuda by default
  3. Define the environment variables
    – The PATH variable needs to include /usr/local/cuda/bin
    DYLD_LIBRARY_PATH needs to contain /usr/local/cuda/lib
    The typical way to place these values in your environment is with the following commands:
    export PATH=/usr/local/cuda/bin:$PATH
    export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PAT
    To make these settings permanent, place them in ~/.bash_profile
  4. Install CUDA SDK
    The default installation process places the files in/Developer/GPU Computing

To compile the examples, cd into /Developer/GPU Computing/C and type make. The resulting binaries will be installed under the home directory in /Developer/GPU Computing/C/bin/darwin/release

Verify the installation by running ./deviceQuery, the output of which should be something like this

Sample CUDA deviceQuery Program

Now, you are all set to start with CUDA programming!



  1. CUDA getting started guide for Mac OS

Why Apple and Mac OS? – II

What’s a hardware with out software? Many think they need to buy many softwares for Mac OS. Frankly, until now I haven’t spent more than $100 on my software. Mac OS gives a very colorful environment to play with: you have Mach, FreeBSD, a nice driver development environment, and a lot of the system’s source code to go with it.

Windows is the odd-man out here. So, let me not talk about it. 😛 When I started using Linux during my college, I wondered why do people still use Windows?! (Ok…you can’t play games like in Windows). I have made heavy use of Linux in academics and now in my job. You can get a lot of the same, or similar software on Mac OS X. You can compile it yourself like you do in linux. Using Macports, you can install most of the softwares like you do on a linux machine. Like ‘sudo apt get install’ you have ‘sudo port install‘ on Mac OS. Mac OS  is representative of a “best-effort” approach – Apple took technology they had collected over the years, along with technology that had flourished in the open source world, and put together a reasonable system.

Personally, I prefer Mac OS to Linux. I found installing new stuff on Mac way easier than other platforms. I mostly use C/C++ in my coding. Once Xcode is installed, voilà! You have the necessary libraries requied to kick-off programming. Macs come with Ruby and Python installed, and an incredible C/C++/Objective C development environment from Xcode environment. The terminal base in linux is very similar to Linux. So, compiling and executing a program via terminal is the same as Linux. Newer versions of Xcode comes preinstalled with OpenCL. As a GPU progrmmer, that makes my life more easy. No need to install any extra libraries. Installing CUDA is also very easy. And also libraries like OpenGL are very easy to install. If you are familiar with linux, then you will be experiencing the same with a little make-up 😉

And I have also started with iPhone programming, and to deploy apps must have a Mac hardware!  You can’t test iPhone apps on a non-Mac hardware. Here again, Xcode simplifies things a lot. Mac OS runs pretty much all open source software flawlessly and, of course, it comes with all of the Unix command line tools and a well-built Terminal app for running them. So, those who are used to the terminal, you will not miss anything.

Here is a list of some of the softwares available for Mac OS.

The Spotlight feature easily lets you search any files on the disk. There are many productivity apps like Garagegand, iPhoto, iMovie, iWeb. Garageband is useful to start any project involving music. You can actually tune your guitar using the mic on a Mac machine. iPhoto lets you organise your photos accordingly. When you attach a new device, Mac OS will mostly recognise that and install the necessary drivers. Since the Mac hardware is so tightly controlled by Apple, Mac OS includes all of the drivers for everything, from graphics to USB, and things just tend to work. And another feature, Universal Access, using which even the blind users can interact with Mac software. Its called Voice Over and it’s exaplained here.

Then there is a great back up feature in Mac OS. Its called Time Machine. It’s as simple as clicking a ‘yes’ button when you put a hard-drive to use as a back-up. And if you want a Mac hardware but prefer working with Linux/windows environment, there’s way for that too. Firstly, Windows Parallels, which is a commercial software where you can install Linux or Windows in Mac OS and access them from. If you want a multi-boot system, you can use Boot Camp, which comes preloaded with Mac OS. It assists users in installing Windows/Linux through non-destructive partitioning of the hard-drive.

Everything said, I prefer to work with a Mac any day over other machines! But…

“Talk is cheap, I will show you the codes from next post” 😉

Why Apple and Mac OS? – I

My friends constantly keep pestering me about my Macbook (2010 model), which sadly is discontinued now, and cant wait to mock me when I run into any trouble with my machine. Recently, I had an issue with my machine where during boot-up it stood still at a white screen with no activity for hours. Well, this issue has a name – Macbook white screen of death! After googling, I found that this was a common issue. But I had to shed some bucks to get it working again. I wanted to upgrade my machine with a better RAM and easy to carry around. So, I ordered a Macbook Air. When my friends came to know about this they asked me – “Why again?”. So, I am writing this post which prompted me to do so. These are my personal views. 😉

I bought my Macbook 2 years ago and I loved it since then. It took me a few days to get acquainted with the new OS but the smooth interface mesmerized me. The multi-touch trackpad is my favorite. If you have used it, you know exactly what I’m talking about. The worst thing about multi-touch on Mac is having to go back to a Windows laptop — you get so used to two and three finger taps that it’s nearly impossible to stop doing it!

Let me break the post into two parts:

  1. Why apple hardware?
  2. Why software?

To use Mac OS, I need not necessarily buy a macintosh machine. I can install Hackintosh on any machine which simulates a Mac OS supporting all the softwares and updates with no issues. Then why apple hardware? As I said earlier, my favorite part in my machine is the multi-touch trackpad. I have worked with few other machines which claim to have a multi-touch trackpad but I found all of them to be jerky. No interface was as smooth. And then the looks. You can’t stop staring at a Macbook with the apple logo glowing. 😉
The apple hardware is in fact expensive. Many  think that Apple is unnecessarily making us buy their machines in order to use Mac OS X. It might be their business strategy! Apple machines are not just pretty, stylish or good-looking, a lot of engineering goes into building them. Take MacBook Air, for example. Its unibody enclosure is machined from a solid block of aluminum. The result is a notebook that is thin and light, looks polished and refined, and feels strong and durable. The magnetic MagSafe power connector breaks cleanly away from the notebook if you trip over the power cord. And who doesn’t love a backlit keyboard which glows in low-light ambience environment. And the battery life – an amazing 7 hours per recharge! Well, these are only some of the features.

If you’ve never, take a look at the inside of a G5 PowerMac. Do an ioreg -l -w 0 on that machine. There are nine fans and twenty-one temperature sensors on it (might vary depending on the model). It’s amazingly quiet.

So, apple hardware and Mac OS is like a package deal. To get the best performance and ease of usability you need to have both.