How do I make a program auto-start every time I log in?
Solution 1
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:
Open a terminal, and run
gconf-editor
.Navigate to /apps/gnome-session/options.
Enable the option: auto_save_session.
(NOTE: this may slow system boot, and has not been throughly tested.)
Solution 2
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.
Solution 3
12.04 (Unity)
We can add applications to the "Startup Applications" by opening the menu entry on the top panel right side:
14.04 (Unity) and later
We can search the Dash for "startup applications"
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:
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
:
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.
Solution 4
If you are using the GNOME Desktop Environment, then this is rather simple to accomplish.
- Go to
System>Preferences>Startup Applications
,
- Now you can either add an application by clicking add,
- And adding the application/script you want to run on startup,
- Or you can add an application by dragging the launcher you wish to add from the Application menu to the Startup Applications screen.
Solution 5
Another, possibly simpler, option would be to go to menu System/Preferences/Startup applications, then choose the "Options" tab and tick "Automatically remember running applications when logging out"
This will start up any applications you have running when you log out.
Related videos on Youtube
Michael Gundlach
I'm a Moderator - if you have any issues, questions, concerns about the site please feel free to contact me: marco [AT] ceppi [DOT] net or ask on the Ask Ubuntu Meta I have been using Ubuntu as my primary operating system since early 2005 - my prior OS of choice being Debian. I greatly enjoy the Community that has grown around Ubuntu and the standards it's upholding. I'm also now an employee of Canonical working on the Juju project. Github Thing Ohloh! Oh no! Everywhere else @marcoceppiGoogle+Facebook
Updated on September 17, 2022Comments
-
Michael Gundlach over 1 year
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?
-
Admin about 13 yearsI presume
Menu > Preferences > Startup Applications
doesn't suit your needs? -
Admin about 13 years@Kaustubh - it does. But I like generic questions rather than the same question asked multiple times with slightly different programs :)
-
Admin over 9 yearsHow can this be achieved from command line?
-
-
Jason Southwell about 13 yearsI like it clicks imaginary like button
-
Takkat about 13 years+1 but this needs to be handled with care. If one of the apps just running is buggy or crashes the X-Server you may end up with a bad to handle no-fun system (I had that once).
-
Scaine about 13 yearsYeah, I admit - that's why I stopped using it too. There is always "gnome-failsafe" session, I suppose, but I couldn't figure out how to recover my crashed session. That was years ago though. Hard to believe it would happen these days.
-
pinpin890 about 13 yearsi did that but like i remember in 10.10 it has a button that said click here to remember all applications open to be start up automatically (or something like that)
-
Alan about 13 yearsPlease see my edited post.
-
pinpin890 about 13 yearsokay..so its being fixed right? or being "discussed"
-
Alan about 13 yearsThat post is from February when Natty was being tested. There is no other information that goes along with it, but I would assume they are still trying to fix it.
-
pinpin890 about 13 yearsokay ...thank you for informing this information
-
Alan about 13 yearsKevin, please see my updated answer.
-
Alan about 13 yearsDuplicate of askubuntu.com/questions/38988/….
-
Krosan about 13 yearsNo joy for me. I set the flag, but the various terminal windows (with multiple tabs) that I created in the various workspaces before I logged off were not restored when I logged back in.
-
Ib33X over 12 yearsis there something similar for oposite solution when user log-out from unity
-
Pramod H G almost 12 yearsThat's not work on Ubuntu 12.04 - there is only
splash_image
item in the options. I've also tried to addauto-save-session=true
option manually but it didn't help, running applications don't restore after restart... -
Scaine almost 12 years12.04 has removed the "automatically remember" option I show above. You have to search Dash for "Startup Applications" then manually add the entries you want.
-
Jacobo de Vera over 10 yearsThanks for the programmatic approach, that's exactly what I was looking for.
-
mrpw over 10 yearsFor Gnome Shell, you have to open it though Ctrl + F2 and typing gnome-session-properties
-
Nick about 9 yearsIs this working with Unity desktop or i need Gnome desktop? Cause with Unity in 15.04 its not working.
-
Takkat about 9 years@YumYumYum thank you for the notice - updated answer :)
-
Ashhar Hasan about 8 yearsIs the
~/.config/autostart
portable? The other two look to be supported by the GNOME desktop environment and Unity. -
Takkat about 8 yearsIt is available on all X-systems where we had ot specified a different directory spec. See specifications.freedesktop.org/autostart-spec/0.5/ar01s02.html