Init.rb file location

Where is the init.rb that everyone is talking about?

I have three raspberry pi 4’s in front of me, with a new download of sonic pi from the web, not through terminal. None of them have a file called init.rb anywhere, what am I missing? Where is that file supposed to be?
There is a config folder, but no files in that folder.

I am looking to start playing immediately on boot of a headless raspberry pi getting midi input.

Hi @louiselessel :slightly_smiling_face:
I see that if you have installed Sonic Pi for the first time, the init.rb file is not created automatically. (Or at least, that is how it appears to be, after I simulated this by renaming Sonic Pi’s .sonic-pi folder and opening Sonic Pi, to pretend that this was a fresh install). I’ll double check this behaviour, in case it was actually our intention here that the init file should be automatically created for you.

The default location is indeed in the ~/.sonic-pi/config folder. It will be just a matter of creating a file in there called init.rb and filling it with whatever Sonic Pi code you wish to run on Sonic Pi startup.

(There are examples of this and other files that live in the config folder, at the following link):

Hi there,

just to confirm, the init.rb file doesn’t exist until you have started Sonic Pi at least once. “Installing” Sonic Pi is just a matter of putting the app in the program files/app directory and doesn’t modify anything else. Only when you start the program does it check to see if you have a ~/.sonic-pi directory and if not it creates it. This is where all the config/log/buffers are stored so that Sonic Pi remembers the state of the app when you close it so that it’s the same when you open it again.

1 Like

Hi both, thank you for the quick reply.
I have opened and closed sonic pi many times after the install and I have things in at least buffer number zero. The init.rb file did not get created.

I also tried making the directory in config/user examples/ and putting a file named init.rb in it. Nothing happened. Is there a good way to check the init.rb does run? Some init.rb demo code I could check?

I do see the buffers in the log folder though.

Hi there,

that’s very curious. Firstly, the buffers shouldn’t be in the log folder, it’s very strange that they are for you, they should be inside ~/.sonic-pi/store/default. The init.rb file should be found at ~/.sonic-pi/config/init.rb.

What do you see inside your ~/.sonic-pi folder? For me, it’s the sub-folders: config, log and store. These store the following:

  • config - configuration files: init.rb, audio-settings.toml,, gut-settings.ini`
  • log - a number of log files ending in .log and a history directory of older log files.
  • store - two sub folders default and system which are the home for your auto-saved buffers, and various other things.


can you send us a tree command result of your .sonicpi ?

Hi. Yes I will do that. I am on a flight the next two days. But will send it Monday!

Thank you !

And I think the files are in the correct folder as you said Sam. I had packed down the pi’s for the day when I wrote that. Let me double check.

  • Louise
1 Like

Hi, I am so sorry about the late reply. It appears it was not sent through the email.

Got the pi again and this is what the directory looks like (I have code in 3 of the stores in Sonic Pi and a saved file in my Documents folder as well):

Is it in the wrong place? There is no init.rb

Got the pi again and this is what the directory looks like (I have code in 3 of the stores in Sonic Pi and a saved file in my Documents folder as well):

Is it in the wrong place? There is no init.rb

Additional images of what is in the directories:

Hi @louiselessel - could you look inside the config directory, the init.rb file should be found at ~/.sonic-pi/config/init.rb .


Unless I’m missing something the link shared above includes a screenshot of the (empty) config folder…

Oh, I missed that, thanks for catching it. Absolutely no idea what’s going on here. Perhaps there’s something in the logs that is explaining this.

hmmm… Could I try to create a init.rb file in there?
If so is there some code that I could put in there to test?

Will post content of log files later.

Sure, that’s worth a try. You can put anything in the init.rb file that you would normally put in a standard Sonic Pi buffer - it should get evaluated as you boot the app.

Ok I will try that. But it is strange that the same issue is happening on three raspberry pi 4s and one raspberry pi 3.

Sonic Pi is supposed to be in the home directory on pi right? that can’t be the issue?

I have uploaded the log files here. Not sure what to look for in terms of errors

Interestingly one of your log files states:

Could not find init.rb file: /home/pi/.sonic-pi/config/init.rb

I would definitely try creating this manually and seeing if it works. Simply putting sample :loop_amen in there should make the amen break play on app start… fingers crossed!

Hi Sam!
That worked on the pi 3! Fingers crossed for the pi 4’s!
My associate is working on those now will have him test and get back to you.

1 Like

I tried having it print something on the pi 4 last week but that did nothing, so I was confused as to where this goes. Since there was no visual output either. I think it’d definitely be a nice user friendly feature request if there was a buffer that you could find inside the gui of sonic pi that would just auto play on boot. Like buffer 0 through 9 + buffer “boot”

Actually, the init.rb file is silent in terms of visual output and log by design. It was really just intended for people to load functions and other data that is common for their music projects.

Out of interest, what are you specifically trying to achieve?

Just a thought, but is having text output of init.rb optionally visible (but silent by default) via a setting agreeable? Seems like it is harmless enough…