How to Install and Setup OneDrive Client in Ubuntu 22.04

This is a step by step beginners guide shows how to install and setup OneDrive client in Ubuntu 22.04 to sync files between local machine and Microsoft cloud.

OneDrive is a file hosting service by Microsoft. It so far does not have an official app for Linux, but there’s a popular free open-source client works in most Linux. And, here’s the basic how to guide for installing and using it in Ubuntu Linux.

Step 1: Install OneDrive client

Option 1: Install it from system repository

The client package is available in most Linux repositories, including Ubuntu.

For Ubuntu users, simply press Ctrl+Alt+T on keyboard to open terminal. and run command to install it:

sudo apt install onedrive

Option 2: Install from third-party repository

OneDrive package in Ubuntu 22.04 and Ubuntu 20.04 repository is old. If you would like to get the latest version, then here’s a third-party repository available.

1. First, click the link below to go to the OBS repository:

OneDrive 3rd-party OBS Repository

2. In that web page, click on Ubuntu logo, select “Grab binary package directly“, then click download the .deb package for your system.

In case you don’t know which Ubuntu version is currently running, open terminal (Ctrl+Alt+T) and run cat /etc/os-release and dpkg --print-architecture commands to tell.

3. Finally, right-click on your Downloads folder and click “Open in Terminal“, and run command in pop-up terminal to install the .deb package.

sudo apt install ./onedrive*.deb

Step 2: Authorize with your OneDrive Account

Before being able to upload or download files, you have to first authorize the app with your OneDrive account.

1. To do so, simply open terminal (Ctrl+Alt+T) and run command:

onedrive

Then, copy the output link url and open in web browser.

2. In the web page, click “Accept” button to grant permissions to access your OneDrive account.

3. After that, the web page will be redirect to a blank page. Just copy the url of that blank page, and paste into the terminal window and hit Enter.

If done successfully, the terminal will output somethings says ‘Application has been successfully authorized‘.

Step 3: Sync files between local folder and OneDrive cloud.

After authorized the app, you can now try running the client in terminal (Ctrl+Alt+T) by running command:

onedrive --dry-run --synchronize

This command will run the client to test the configuration. No files will be downloaded, uploaded or removed! A OneDrive folder will be created (if not exist) in your user home directory for syncing files.

To start syncing files, run command:

onedrive --synchronize

Or use onedrive --synchronize --local-first to upload local files (from user’s OneDrive folder) first then download from cloud.

For choice, you may sync only single folder only, for example “Pictures” sub-folder under OneDrive directory, by running command:

onedrive --synchronize --single-directory 'Pictures'

Or, do uploading local files only via command:

onedrive --synchronize --upload-only

There’s also --download-only command option to only download differences from cloud to local, and --no-remote-delete to NOT remove files that previously synced but later manually deleted.

Step 4: Sync files automatically

If everything goes OK, you may also start OneDrive as systemd service, so it does the file sync between cloud and local folder automatically.

To do so, simply run command in terminal (Ctrl+Alt+T) to enable the service:

systemctl enable --user onedrive

Then, start it by running command:

systemctl start --user onedrive

Finally, check the service status by running command systemctl status --user onedrive.

Once the service is in active running status, try making difference in either local or cloud OneDrive folder, then check in another side to see if it works.

Step 5: Config OneDrive client

If the default sync options do not meet your need, then, run command to copy example config file to local folder:

sudo cp /usr/share/doc/onedrive/config ~/.config/onedrive/

Then, change the ownership from root to your user:

sudo chown $USER:$USER ~/.config/onedrive/config

Finally, either open file manager (press Ctrl+H to view hidden files/folders), navigate, and click edit the file. Or, run command:

gedit ~/.config/onedrive/config

For Ubuntu 23.10+, replace gedit with gnome-text-editor. For non-GNOME Desktop, replace it with your text editor, or use nano command line editor works in most desktops.

When file opens, un-comment (remove # at the beginning) to enable any option and change its value as you want, such as sync folder, exclude files/folders, upload only or download only, and more, and finally save the file.

Finally, run command systemctl restart --user onedrive to restart service to apply the changes. For more about how to use OneDrive client, see the official docs.

Uninstall OneDrive:

If you don’t to use the client anymore, open terminal (Ctrl+Alt+T) and run command to stop and disable the service:

systemctl disable --now --user onedrive

Then, remove the client package by running command:

sudo apt remove --autoremove onedrive

For choice, you may clear the leftovers by deleting them via commands:

sudo rm /etc/logrotate.d/onedrive
rm -R ~/.config/onedrive