Setting Up Org-Roam Directories and Syncing Multiple Machines (Linux, Android, & Windows)

Hi All,

tl;dr

How does one setup an org-roam directory / database on multiple machines/devices?

The Objective

I am moving from a markdown notes system that I originally started in OneNote, moved to Obsidian, moved to VSCodium (where I discovered org-mode and then saw that the VSCode package was very limited), and am wanting to go forward solely using emacs with org-mode/org-roam. My notes system is a directory with subdirectories, which I will explain further below.

How should I setup up my org-roam folder?

What I’ve Been Using

I have my markdown files , templates, and some org-mode TODO lists that I sync, using Syncthing, between my home Linux PCs, Android devices (Orgzly), and my work Windows 11 PC. I currently have a directory similar to the following: ~/Syncthing/Notes/ for Linux AND "C:\Users\USER$\Documents\Syncthing\Notes\" on Windows.

In my Notes directory, I have Work and Personal subdirectories. On my home PCs, I can access everything. On my work PC, I only can access the Work subdirectory. I don’t want my personal notes accessible on a work PC that I don’t own.

Where I’m Stuck

I would like to continue using Syncthing to sync my org-roam directory, likely with the .stignore file to have each local machine update it’s own .db file. On Linux and Android machines I think I should be able to use ~/Syncthing/org-roam or something to that effect and have org-roam find the files via (org-roam-db-location "~/Syncthing/org-roam/org-roam.db") and (setq org-roam-directory ("~/Syncthing/org-roam")). I am wondering how to marry up the Linux/Android and Windows systems. Where do I place the sync’d folder and how to let emacs/org-roam point to the correct path on Windows?

Table of What I Think Should be Executed

PC User Syncthing Access
Linux Desktop zonsopkomst ~/Syncthing/org-roam Work & Personal subdirectories
Linux Laptop zonsopkomst ~/Syncthing/org-roam Work & Personal subdirectories
Android Tablet zonsopkomst /storage/emulated/0/Syncthing/org-roam Work & Personal subdirectories
Android Phone zonsopkomst /storage/emulated/0/Syncthing/org-roam Work & Personal subdirectories
Windows 11 Desktop My real name, nobody calls me zons… :frowning: C:\Users\USER$\Documents\Syncthing\org-roam Work subdirectory ONLY

Org-roam init.el Section

(use-package org-roam
  (org-roam-directory "~/Syncthing/org-roam/")
  :bind (("C-c n l" . org-roam-buffer-toggle)
         ("C-c n f" . org-roam-node-find)
         ("C-c n i" . org-roam-node-insert))
  :config
  (org-roam-setup))

Warning on Windows 11

Error (use-package): Failed to parse package org-roam: Wrong type argument: symbolp, (org-roam-directory "~/Syncthing/org-roam/") Disable showing Disable logging

gcc

From org-roam Instructions

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\WINDOWS\system32> MSYS2
PS C:\WINDOWS\system32>

Opens MSYS2:

USER$@DESKTOP- MSYS ~
# pacman -S gcc
resolving dependencies...
looking for conflicting packages...

Packages (8) binutils-2.41-3  isl-0.26-1  mpc-1.3.1-1  msys2-runtime-devel-3.4.9-2
             msys2-w32api-headers-11.0.1.r0.gc3e587c06-1
             msys2-w32api-runtime-11.0.1.r0.gc3e587c06-1  windows-default-manifest-6.4-1
             gcc-13.2.0-2

Total Download Size:    45.52 MiB
Total Installed Size:  346.28 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 msys2-w32api-headers-11.0....     5.2 MiB   672 KiB/s 00:08 [###############################] 100%
 binutils-2.41-3-x86_64            5.5 MiB   672 KiB/s 00:08 [###############################] 100%
 msys2-runtime-devel-3.4.9-...   339.2 KiB   614 KiB/s 00:01 [###############################] 100%
 mpc-1.3.1-1-x86_64               78.5 KiB   167 KiB/s 00:00 [###############################] 100%
 windows-default-manifest-6...  1388.0   B  1022   B/s 00:01 [###############################] 100%
 isl-0.26-1-x86_64               745.0 KiB   672 KiB/s 00:01 [###############################] 100%
 msys2-w32api-runtime-11.0....     2.0 MiB  1129 KiB/s 00:02 [###############################] 100%
 gcc-13.2.0-2-x86_64              31.7 MiB  4.56 MiB/s 00:07 [###############################] 100%
 Total (8/8)                      45.5 MiB  2.59 MiB/s 00:18 [###############################] 100%
error: failed retrieving file 'gcc-13.2.0-2-x86_64.pkg.tar.zst' from mirror.msys2.org : Failed to connect to mirror.clarkson.edu port 443 after 10013 ms: Timeout was reached
error: failed retrieving file 'msys2-w32api-runtime-11.0.1.r0.gc3e587c06-1-x86_64.pkg.tar.zst' from mirror.msys2.org : Failed to connect to mirror.clarkson.edu port 443 after 10005 ms: Timeout was reached
error: failed retrieving file 'isl-0.26-1-x86_64.pkg.tar.zst' from mirror.msys2.org : Failed to connect to mirror.clarkson.edu port 443 after 10018 ms: Timeout was reached
warning: too many errors from mirror.msys2.org, skipping for the remainder of this transaction
(8/8) checking keys in keyring                               [###############################] 100%
(8/8) checking package integrity                             [###############################] 100%
(8/8) loading package files                                  [###############################] 100%
(8/8) checking for file conflicts                            [###############################] 100%
(8/8) checking available disk space                          [###############################] 100%
:: Processing package changes...
(1/8) installing binutils                                    [###############################] 100%
(2/8) installing isl                                         [###############################] 100%
(3/8) installing mpc                                         [###############################] 100%
(4/8) installing msys2-runtime-devel                         [###############################] 100%
(5/8) installing msys2-w32api-headers                        [###############################] 100%
(6/8) installing msys2-w32api-runtime                        [###############################] 100%
(7/8) installing windows-default-manifest                    [###############################] 100%
(8/8) installing gcc                                         [###############################] 100%
:: Running post-transaction hooks...
(1/1) Updating the info directory file...

USER$@DESKTOP- MSYS ~
# where gcc
C:\tools\msys64\usr\bin\gcc.exe

Okay, looks good so far, and added C:\tools\msys64\usr\bin\gcc.exe to my Windows Environmental variables. But I still cannot run ‘M-x org-roam-db-autosync-mode’ as there is no command in emacs and is probably occuring because I have no org-roam directory or org-roam database yet.

I appreciate any advice that you can provide!

Thank you,
zons

Sorry it’s hard to read all your detail but I hope the following will respond to most of your issues.

For Windows,

  1. Download the latest release 29. It has sqlite built-in and works (I use it). No need for gcc or msys2
  2. To use it, download the package emacsql-sqlite-builtin in addition to emacsql. See this post

Do not sync the database file. They should be built for each machine.

I don’t think your Android mobile phone and tablet can use Emacs and org-roam (orgzly can edit org files but it does not have the backlinks from org-roam, but I suspect you know it and I believe it’s not an issue for you).

For settings in Emacs, there is no difference between Windows and Linux for org-roam. You can use sqlite-builtin: (setq org-roam-database-connector 'sqlite-builtin). Make sure to set the correct org-roam-directory for each machine.

Check the configuration example in README of the project repo on GitHub. You have a syntactic error in the way you use use-package. The second line immediately after use-package org-roam should not start with (org-roam-directory…. That seems to be what the error message is saying; it’s not just Windows, but Linux won’t work, either.

If you are reading this from your email, I have extensively edited my previous post and the version on the email is obsolete. Please check back the web.

Thanks @nobiot. I also have a Matrix conversation going with yantar92 at You're invited to talk on Matrix that has taken care of some of my issues.

Should I uninstall emacs 28 and MSYS2 before installing emacs 29? I have installed emacs through chocolatey. I see that winget has it as the latest, but chocolatey is still 28, unless I would use 29.

I don’t know what chocolaty does to the system to manage the packages, but I would remove 28 if I were you (it probably adds environmental variable for itself). I’d just simply download the binary file from the official GNU/Emacs website/mirror.

You don’t need to remove msys2.

If you want to use 28, I have a step-by-step guide for Windows 10. 11 is the same process.

Thanks @nobiot . I am familiar with your works. I haven’t followed your guide 100% due to using straight as my emacs package manager, but I have installed MSYS2 using the Org-roam User Manual instructions, which appear in line with your instructions. I am wondering if my Windows environment path is set correctly. I have included these:
image
as I didn’t quite understand the above Org-roam User Manual instructions and have never had to edit my Windows environment path before. But this is what where gcc had output.

The good news is that I am no longer receiving the Warning on WIndows 11 message that I originally posted above after following yantar92’s instructions on Matrix chat. My messages buffer is clean now.

gcc is needed to compile the sqlite source provided by emacsql-sqlite. MSYS2 is needed to get gcc easily on Windows.

All this is requires for org-roam up until Emacs version 28 on Windows. So if you want 28, you can keep going.

If you have Emacs 29.1 onward on Windows, sqlite is built-in within Emacs itself, so you won’t need gcc (and msys2 for this reason).

Either way, good luck. You can come back here if you get stuck.

I don’t think straight is a good option on Windows simply because it requires additional efforts to get Info documentation (user manuals—including org-roam’s) that you can access from within Emacs offline. The situation might have improved. This is just my observation and personal preference.

Thanks @nobiot. Well, it appears that using the MSYS2 method to install gcc easily on Windows worked, but when I run M-x org-roam-db-autosync-mode displays the message:

No EmacSQL SQLite binary available: (Could not find C compiler, skipping SQLite build)

so I can only imagine that something is incorrect with my environment path. But I don’t understand what it may be.

If you have any more suggestions, I will attempt before uninstalling 28 and going the 29 route. It’s just that 28 is working, and I hope 29 would work, but there’s always the odd chance I make the situation worse.

EDIT:

  1. Installed sqlite mingw using chocolatey
choco install sqlite mingw -y

In Windows Powershell, msys2, and executed the following commands

pacman -Syu
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

Opened emacs

M-x org-roam-db-autosync-mode

emacs Messages Buffer output:

Compiling EmacSQL SQLite binary...done
Clearing removed files...done
Processing modified files...done

Running M-x org-roam-db-autosync-mode in emacs results in:

"c:/Users/Zonsopkomst/AppData/Roaming/.emacs.d" failed with status "exited abnormally with code 49" and result Invalid face attribute :foreground nil [3 times]

I think I have had enough of this today. Will be back tomorrow. :slight_smile:

Hopefully these posts will help anyone else running into this issue:

So late last night I C-c f n and created a note and viola, the org-roam database was created. I now have org-roam functioning on both Windows and Linux and the files are shared via Syncthing using an .stignore file. I have created a directory ~/Syncthing/org-roam with subdirectories /Personal and /Work and have added Personal to my .stignore file so that it will NOT be shared to my Windows work computer.

That being said, I am not well versed on how org-roam functions, but I am hoping that the database on each machine will function correctly as I learn and understand org-roam.

@nobiot Thanks for your help and for reference to your instructions!

1 Like

Letting each machine generate its own db file is the way Jethro has design it to work (“it’s a cache”) – so what you have done is the standard way.

One thing you might like to note is this: Org-roam updates the database for all new and changed files when you activate org-roam-db-autosync-mode (or, equivalently, when you run org-roam-setup, which activates the mode). Other than this, Org-roam only updates the db for each file you change in the machine.

This is good for performance, but it also means … if you keep running your personal Linux machine for a long time, while you update your work notes in your Windows machine, the notes get synced with Synchthing but Org-roam in your Linux machine will not automatically update the database with the changes / new work notes.

If you are a type of person who shuts down Emacs or Linux PC often (like me), then you won’t even see this. But if you tend to keep Linux (or Windows) machine running days and weeks, you should know about this.

None of this breaks your note files or Org-roam db files. It’s just the cache db is not in sync, so you might not see some of notes in another machine, and scratch your head wondering what’s happening.

In this case, simply run org-roam-db-sync manually. Org-roam then scans all the new and changed files (based on the time stamp) and add them to the db.

Thanks. Good to know. I will keep that in mind. I shutdown each machine daily, except for my work machine, so it is good to to be aware of how the database updates.