Follow the steps below, and see if it helps...
[Optional, you may choose to not install Xcode as long as you have any text editor] On a Mac, make sure you have installed Xcode first of all. It's available on the Mac App Store for free, but is a hefty download. So, once downloaded, move further.
Now, download the CS50 library from here.
Now are the important steps, so, pay attention from here on
Open up a new terminal window, from the Launchpad(or from Applications). Just type
cd ie. Type "cd" and leave a space
Open the downloads folder, there you'll see the "library50-c-5" folder. Drag that folder from there to the terminal window. Once dragged successfully, you should be able to see
cd /Users/yourname/Downloads/library50-c-5 where the path may vary according to your Username and downloads folder... Now, press enter.
Now execs cute the following commands(as instructed by CS50 manual) step by step:
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
rm -f cs50.o
chmod 0644 cs50.h libcs50.a
sudo mkdir -p /usr/local/include
sudo mv -f cs50.h /usr/local/include
sudo mkdir -p /usr/local/lib
sudo mv -f libcs50.a /usr/local/lib
rm -rf library50-c-5
Whoops, a lot of work, right, I know... :) just know that you'll have to enter your password(your Mac user password) once, or maybe twice in the process. Also, in your question, you mention facing some errors, what are those errors ? Any that you face during execution of these commands ? If you still face those, consider detailing the errors.
Plus, that's it.
To test out the CS50 library, open a text editor(or even Xcode), and create a new file called
hello.c and type a simple program that uses the CS50 library. Include it to your program using
#include <cs50.h>. Now, close the file and either try compiling it on Xcode(if you downloaded it at the first place) or open up a terminal window, change your directory to the one the file
hello.c is (using cd) and then enter the following command:
gcc -g hello.c -o hello -lcs50 -lm
And now, if you face no errors, congrats, you have installed the CS50 library on your Macintosh. Try out your program using
./hello to see if all works correct. It must do so if you followed all the steps above correctly.
Best of luck installing the CS50 library on your Mac, and happy coding...