In this comprehensive guide, we will walk you through the process of preventing Ubuntu from sleeping when you close the laptop lid. This is a common challenge for Ubuntu users who want their systems to continue running tasks even when the lid is closed.
To prevent Ubuntu from sleeping when closing the lid, you have two main options. The first option is to use GNOME Tweaks, a versatile tool that allows you to customize power behavior. The second option is to modify power settings via the terminal using the
gsettings command. Both methods involve disabling the automatic sleep feature when the laptop lid is closed.
- Understanding the Default Behavior
- Solution 1: Using GNOME Tweaks
- Solution 2: Modifying Power Settings via Terminal
Understanding the Default Behavior
By default, when you close the lid of your laptop, Ubuntu goes into sleep mode. This is a power-saving feature designed to conserve battery life. However, there may be times when you want your laptop to continue running even with the lid closed.
Solution 1: Using GNOME Tweaks
GNOME Tweaks is a versatile tool that allows you to customize many aspects of your GNOME desktop, including power behavior.
Step 1: Update Your Package List
Open a terminal and update your package list by running the following command:
sudo apt update
This command updates the list of available packages and their versions, but it does not install or upgrade any packages.
Step 2: Enable the Universe Repository
universe repository houses free and open-source software maintained by the community. Run the following command to enable it:
sudo add-apt-repository universe
Step 3: Install GNOME Tweaks
Next, install GNOME Tweaks by running:
sudo apt install gnome-tweaks
This command installs the GNOME Tweaks tool.
Step 4: Modify Power Settings
Launch GNOME Tweaks, go to the “General” tab, and under the “Suspend when laptop lid is closed” option, select “Off”. This disables automatic sleep when closing the lid.
Solution 2: Modifying Power Settings via Terminal
If you prefer using the terminal, you can directly modify the power settings.
Step 1: Prevent Sleep on AC Power
Open a terminal and run the following command to prevent sleep when the laptop lid is closed while on AC power:
gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'nothing'
gsettings is a command-line interface for GSettings, which is a system for storing application preferences. The
set command is used to change a setting, and
'nothing' is the value we’re setting, which tells the system to do nothing when the lid is closed.
Step 2: Prevent Sleep on Battery Power
Run the following command to prevent sleep when the laptop lid is closed while on battery power:
gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action 'nothing'
This command is similar to the previous one, but it applies when the laptop is running on battery power.
These are the two main methods to prevent Ubuntu from sleeping when closing the lid. Remember, these settings might affect your laptop’s battery life, so use them wisely. If neither of these solutions work for you, it’s possible that there may be other factors or configurations affecting the sleep behavior. In that case, check for any error messages or logs related to power management.
Yes, you can modify the power settings directly via the terminal without installing any additional software. Please refer to Solution 2 in the guide for the step-by-step instructions.
Yes, preventing Ubuntu from sleeping when closing the lid may consume more battery power compared to the default behavior. It is important to use this feature wisely and consider the impact on your laptop’s battery life.
Yes, you can modify the power settings separately for AC power and battery power. Please refer to Solution 2 in the guide for the specific commands to prevent sleep on each power source.
Yes, there could be other factors or configurations that affect the sleep behavior. If the solutions provided in the guide do not work for you, it is recommended to check for any error messages or logs related to power management. Additionally, make sure your Ubuntu system is up to date and all relevant drivers are properly installed.