The CS50 Library is a suite of C, Ruby, PHP, and Python code designed to simplify certain tasks, particularly user input (for C) and authentication (for PHP, Python, and Ruby).

C

The CS50 Library for C provides the functionality documented in cs50.h.

The CS50 Library for C comes pre-installed in the CS50 Appliance, but it’s also possible to install it on your own machine. However, we strongly recommend that you use the CS50 Appliance, as it comes preconfigured not only with the CS50 Library for C but also with everything else that you need to take (or "take") CS50, including gcc, gdb, and more.

Installation

Linux

If running Linux, you should include the CS50 Library’s header file atop your own as follows:

#include <cs50.h>

Note the use of angled brackets instead of quotes.

But first you must install the library itself, per the below.

CentOS, Fedora, RedHat

First become root, as with:

su -

Then install the CS50 Library as follows:

yum -y install gcc
wget http://mirror.cs50.net/library50/c/library50-c-5.zip
unzip library50-c-5.zip
rm -f library50-c-5.zip
cd library50-c-5
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf library50-c-5
Debian, Ubuntu

First become root, as with:

sudo su -

Then install the CS50 Library as follows:

apt-get install gcc
wget http://mirror.cs50.net/library50/c/library50-c-5.zip
unzip library50-c-5.zip
rm -f library50-c-5.zip
cd library50-c-5
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf library50-c-5

Mac OS

  1. Download and install Xcode.

  2. Download and unzip library50-c-5.zip.

  3. Open Applications > Utilities > Terminal, and navigate your way to the CS50 Library’s directory, as with cd.

  4. Execute the commands below, entering your password if prompted:

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
cd ..
rm -rf library50-c-5

After installing the CS50 Library, you can include its header file atop your own code with:

#include <cs50.h>

Note the use of angled brackets instead of quotes.

Windows

It depends on your compiler, but odds are the simplest method of installation is to:

  1. Download and unzip library50-c-5.zip.

  2. Copy cs50.c and cs50.h into the same directory as your own code.

After installing the CS50 Library, you can include its header file atop your own code with:

#include "cs50.h"

Note the use of quotes instead of angled brackets.

Changelog

PHP

The CS50 Library for PHP simplifies use of CS50 ID. It comes pre-installed in the CS50 Appliance, but it’s also possible to install it on your own machine.

You’ll find that we’ve included Janrain’s Janrain OpenID Library for PHP5 in the CS50 Library’s own share folder.

Installation

Linux

Be sure to install the CS50 Library as root (as via sudo). After installing the CS50 Library, you can include its header file atop your own code with:

require("CS50/CS50.php");

See CS50 ID’s HOWTO for usage.

CentOS, RedHat
wget http://mirror.cs50.net/library50/php/library50-php-4-0.noarch.rpm
rpm -ivh library50-php-4-0.noarch.rpm
rm -f library50-php-4-0.noarch.rpm

Fedora

yum install http://mirror.cs50.net/library50/php/library50-php-4-0.noarch.rpm

Debian, Ubuntu

apt-get install php5 php5-curl php5-gmp php5-xml
wget http://mirror.cs50.net/library50/php/library50-php-4.zip
unzip library50-php-4.zip
rm -f library50-php-4.zip
chmod -R a+rX library50-php-4
mkdir -p /usr/share/php
mv library50-php-4/CS50 /usr/share/php/
rm -rf library50-php-4

Mac OS

  1. Download and unzip library50-php-4.zip.

  2. Unzip it wherever you’d like to install it, ideally outside of public_html and DocumentRoot for security’s sake.

After installing the CS50 Library, you can include its header file atop your own code with:

require("/path/to/CS50/CS50.php");

See CS50 ID’s HOWTO for usage.

Windows

  1. Download and unzip library50-php-4.zip.

  2. Unzip it wherever you’d like to install it, ideally outside of your IIS Web Site Home Directory (if running IIS) or outside of public_html and DocumentRoot (if running Apache) for security’s sake.

After installing the CS50 Library, you can include its header file atop your own code with:

require("/path/to/CS50/CS50.php");

See CS50 ID’s HOWTO for usage.

Changelog

  • 1.6

    • Fixed bugs whereby E_DEPRECATED was not, in fact, disabled.

    • Removed need to specify a directory for a filesystem-based store (i.e., STATE).

  • 1.5

    • Suppressed mkdir warning (when path for state already exists).

  • 1.6

  • 2

    • Transitioned to Fall 2012’s style.

    • Updated Janrain library to avoid references-related errors.

  • 3

    • Updated Janrain library to 11bd8e4277.

    • Removed .git directory from Janrain library.

Python

First, install the latest version of Python, which should come with easy_install. We will use pip to install the CS50 Library. To install pip, simply type

easy_install pip

in a terminal window. You may need sudo privileges to complete the installation. To then install the CS50 Library, type

sudo su - -c "pip install cs50"

in a terminal window.

Ruby

First, install the latest version of Ruby, which should come with RubyGems. To install the CS50 Library, simply type

gem install cs50

in a terminal window. You may need sudo privileges to complete the installation.