Programming Environment Extras

We use Ubuntu Linux as our main programming environment, for a number of reasons. This page covers a number of things we need to be aware of to help use and maintain a Linux computer.

Ubuntu Shortcuts

Knowing some simple shortcuts will help you do your programming work in linux.

Switch windows

Alt-tab

top

Updating Ubuntu

Running updates is a good idea; it keeps your computer functioning appropriately.

From the terminal

By taking this class, you have some interest in working with computers in a powerful way. The terminal is the most powerful way to use a linux computer, so let's jump in and use it whenever possible.

Open a terminal using the keyboard shortcut Ctrl-Alt-T.

Type the following command, and press enter:

sudo apt-get update

You will have to enter your password. Do this, and watch the information scroll by. Your computer is looking to find out which packages can be updated.

Type the following command, and press enter:

sudo apt-get dist-upgrade

When you run this command, your computer downloads and installs all of the updates that were identified by the previous command.

top

Basic Terminal Commands

Packages

Install a package:

sudo apt-get install package_name

Uninstall a package, but keep its configuration files (dependencies?):

sudo apt-get remove package_name

Remove a package, and its configuration files (dependencies?):

sudo apt-get remove --purge package_name

Python

Start a Python interpreter, using the default version of Python on your system:

python

Start a Python interpreter, using a specific version of Python:

python3.3

Exit out of the Python interpreter:

Ctrl-D

top

Terminal Shortcuts

There are a few things that will help you become comfortable using the terminal.

Open a terminal:

Ctrl-Alt-T

Scroll through your previous terminal commands:

up arrow, down arrow

Clear output from your terminal screen. You will still be able to scroll up and see previous output.

Ctrl-L

top

Installing Python 3.3 on Ubuntu 12.04

Ubuntu is still using Python 2.7 by default. It is fairly easy to install Python 3.3, however, and then be able to choose the version of Python you want to use.

Add the "deadsnakes" package archive (ppa) to your system. This archive has a number of older and newer versions of Python. Then install python3.3.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.3

Now that Python 3.3 is installed on your system, you have two options. You can start a default Python 2.7 session by running the command 'python' in a terminal. You can start a Python 3.3 session by running the command 'python3.3' in a terminal.

top

Installing Geany

Geany is one of the text editors we will use for writing programs. Geany is a simple editor, which makes it easy to run programs. Output is shown in a separate terminal window, which gets you used to working in terminals as well.

Open a terminal.

sudo apt-get install geany

Press the windows button, and type 'geany'.

Drag the geany icon to the task bar on the left side of the screen. This creates a shortcut you can use to start geany.

Write a Hello World program, and save it as 'hello.py'.

There are three ways you can run a program in Geany:

  • Build > Execute
  • Press F5
  • Click the icon with three gears on it

You should see a terminal window pop up, with your output in it.

Configuring Geany to use Python3.3

Open Geany, and open a Python Hello World program. If you don't have one on your system, write one and save it as hello.py, and run the program. This makes sure that Geany is trying to run Python programs. When you have a running hello.py program, go to Build >> Set Build Commands.

Under 'Python commands', look for the 'Compile' line. Enter the following in the 'Command' box. Make sure you get the spaces right. You should have 'python3.3' followed by a space, and the rest of the command. If you have 'python 3.3', with a space between python and 3.3, Geany will not be able to run your code.

python3.3 -m py_compile "%f"

Under 'Execute commands', look for the 'Execute' line. Enter the following in the 'Command' box, paying attention once again to the spaces.

python3.3 "%f"

Test your setup with a hello.py file, using Python 3.3 syntax.

top