Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically run at startup on Linux?

Tags:

linux

autorun

How do I programmatically set an executable on Linux to run when the user logs in?

Basically, the equivalent of the HKCU\Software\Microsoft\Windows\CurrentVersion\Run registry key in Windows.

like image 210
Jake Petroules Avatar asked Feb 03 '26 04:02

Jake Petroules


2 Answers

For gnome on Linux, place a .desktop file referring to your application in ~/config/autostart/, the format is fairly simple:

[Desktop Entry]
Type=Application
Exec=foo
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=foo

and you will have to set the exec bit for this file (chmod +x)

If you are shipping on Linux, you should create one of these anyway and place it in the menus.

For KDE on Linux you should create a symbolic link to your program's executable in the folder ~/.kde/Autostart/

like image 144
ternaryOperator Avatar answered Feb 06 '26 13:02

ternaryOperator


If you don't have GNOME, you'd typically put your commands in a shell's .profile or .rc, or in startx if you want this to run in/before your X-environment. You could also hook something into your gdm scripts/.rcs or whatever login manager you have.

like image 42
J. Polfer Avatar answered Feb 06 '26 13:02

J. Polfer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!