How do I make a program auto-start every time I log in?

I frequently need to start several programs that I use every time I start my computer. How can I make it so that whenever I login the program is automatically launched?


To make a program start with Ubuntu:

  • If you're using Unity, search for the program Startup Applications.

  • If you're using Ubuntu Classic, it's under Start Menu > Preferences > Startup Applications.


To make Ubuntu remember your running applications on shutdown:

  1. Open a terminal, and run gconf-editor.

  2. Navigate to /apps/gnome-session/options.enter image description here

  3. Enable the option: auto_save_session.

(NOTE: this may slow system boot, and has not been throughly tested.)


User defined sessions for applications to start after login

An alternative way to automatically start applications after login is to define a user defined session. This has the advantage to use different sessions for different task, each with different applications loaded.

For this purpose we create a custom.desktop file as root in /usr/share/xsessions with the following content (for GNOME/GDM):

[Desktop Entry]
Name=Marco's Crowded Session
Comment=Custom ~/.xsession script
Exec=/home/username/.xsession
X-Ubuntu-Gettext-Domain=gdm

Use any fancy name for your session and replace username by your name of course.

This will run the script .xsession in the HOME directory at login where we can put in any appplications we need to start after login.

The script needs to be named as defined in the .desktop file, that is ~/.xsession in the example given, needs to be made executable and may have a content similar to this:

#! /bin/bash

my-important-app [options] &
second-app [options] &
[...]                       # add other applications
gnome-session [options]

Options for gnome-session may be omitted to load the default session. Give e.g. --session=classic-gnome as option to run Classic GNOME Desktop in 11.04.

Next time we login we will have the choice to start a "Marco's Crowded Session" with all applications from the script running in addition to applications from the gnome-session (or any other desktop manager you chose to start here).

Starting other desktop managers

To start another installed desktop manager replace the last line from the ~/.xsession script with the following:

  • gnome-session --session=ubuntu for standard desktop (with Unity in 11.04).
  • gnome-session --session=classic-gnome for classic GNOME desktop.
  • startkde for KDE desktop manager.
  • startxfce4 for XFCE, or when running Xubuntu.

12.04 (Unity)

We can add applications to the "Startup Applications" by opening the menu entry on the top panel right side:

enter image description here

14.04 (Unity) and later

We can search the Dash for "startup applications"

enter image description here

or we can run the startup preferences from a terminal with

gnome-session-properties

This will open a window where we can see all installed applications that will run on startup. Tick or untick the applications there or choose "Add" to add a new application:

enter image description here

If we know the command to run the application just enter it here in the "Command" line. We may also add an optional "Comment" here.

If we do not know the command we can choose to "Browse..." our file system for installed applications. Many default applications are found e.g. in /usr/share/application:

enter image description here

Select an application to add to autostart.

Command line or programmatical approach

Similar to what the GUI solution above does we can manually add a .desktop file to ~/.config/autostart. The content of this file may be as follows:

[Desktop Entry]
Type=Application
Exec=</path/to/binary or command to execute>
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=<Name_to_be_displayed>
Comment=<optional comment>

Note that in a vanilla installation the directory ~/.config/autostart may not yet exist. We need to create it before we can access it programmatically.