Arduino IDE 2.x Portable (linux)

Based on the idea inside Arduino IDE 2.0 Portable - #23 by divaker
I belive I managed to make a (fully) portable (linux) version..

  • I use "arduino-ide_2.3.6_Linux_64bit.AppImage" placed onto a stick.
  • The first steps are similar to the one described there:
    • let the app create the (config-)dirs, then move them to the portable dir
  • Now I simply use a wrapper script that sets $HOME to my portable path...

Here is my script:

#!/usr/bin/env bash

###############################################################
# Config
###############################################################
DOBACKGROUND="y"	# Call App in Background (with nohup)

###############################################################
# Get current Path
###############################################################

APPDIR="$(dirname -- "$(readlink -f -- "${0}")" )"
cd ${APPDIR}

MOUNT_PATH=$(realpath ${APPDIR}/../..)
NEW_HOME="${APPDIR}/portable"

###############################################################
# Adjust inside ${NEW_HOME}/.arduinoIDE/arduino-cli.yaml:
# libraries: ${HOME}/.arduino15/libraries
# data: ${HOME}/.arduino15
# user: ${MOUNT_PATH}/Portables/Arduino/portable/Sketchbook
###############################################################
yaml="${NEW_HOME}/.arduinoIDE/arduino-cli.yaml"
sed -i -e "s;libraries: .*/.arduino15/libraries;libraries: ${NEW_HOME}/.arduino15/libraries;g" \
       -e "s;data: .*/.arduino15;data: ${NEW_HOME}/.arduino15;g" \
       -e "s;user: .*/Portables/Arduino/portable/Sketchbook;user: ${MOUNT_PATH}/Portables/Arduino/portable/Sketchbook;g" \
       "${NEW_HOME}/.arduinoIDE/arduino-cli.yaml"

###############################################################
# Determine exe
###############################################################
EXE=$(find . -maxdepth 1 -executable -name "${EXE_SEARCH}*.AppImage")
EXE_CNT=$(find . -maxdepth 1 -executable -name "${EXE_SEARCH}*.AppImage" | grep -c ".AppImage")
if [ ${EXE_CNT} -ne 1 ]; then 
  read -p "Invaid # of AppImages found: ${EXE_CNT}"
  exit
fi

###############################################################
# Start Arduiino
###############################################################
if [ "${DOBACKGROUND}" != "y" ]; then
  HOME="${NEW_HOME}" "${EXE}" --no-sandbox
 else
  rm -f nohup.out		# Remove old nohup.out
  HOME="${NEW_HOME}" nohup "${EXE}" --no-sandbox &
  sleep 5
fi

I belive it can easily convert to a Windos/Mac Script (but I don't use Windows/MAC)..

4 Likes

There might be one directory that you might want to delete and that is ~/.config/arduino-ide/.

I've just started creating a portable implementation using bat files under Windows 11 and encountered that some stuff is still there; I think it was a list of libraries although they were not in the sketchbook directory.

I'm using portable installations probably differently than you do; I have several portable 1.8.19 installations for different board packages and even for projects so a board package upgrade or library update does not cause havoc; update warnings are disabled in this setup.

Sorry, didn't really understad what You mean. This Thread is for Arduino 2.x (>1.8.9). I use Version 1,8,x already (see my Thread here).
On Linux, there is no additional dir (neither in V2.x nor 1.x).
But if You use V1.x making it portable is simple, becaus all what is needed is a dir "portabl" byside the exe...

I know that it is for IDE 2.x; I should have been clearer in that, sorry. The directory that I'm referring to is the User data directory as described under https://support.arduino.cc/hc/en-us/articles/4415103213714-Find-sketches-libraries-board-cores-and-other-files-on-your-computer#boards.

@sterretje: First, thanks for Your clarification, it leads me to some more investigations.

Beside to the (extra) directory you mentioned, I found two more (on Linux):
~/.arduinoIDE # settings..
~/.arduino15 # packages
~/Arduino # empty, for Sketchboard ?
~/.config/arduino-ide # Preferences ??
~/.config/Arduino IDE # log

But all that is irrelevant, when using a command-line like:
HOME="${NEW_HOME}" ...
In this case every data goes into "${NEW_HOME}".
So it isn't even necessary to do the preparation steps as described above.
Simply (adapt and) use my (new) script below.
Parts that needs adaption are clearly noticed between "Configuration options" and "End of Configuration options"

Because You wrote:
I'm using portable installations probably differently than you do; I have several portable 1.8.19 installations for different board packages and even for projects so a board package upgrade or library update does not cause havoc; update warnings are disabled in this setup.

OK, I thing about "portable" as the ability to put everything that is need for using an app onto a removable media (pen drive).
But Your approach to uses arduino has it's own authorization. So I modify my script to support both approaches.

If You define PORTABLE_PATH before running the script you may use unlimited installations.
You may write an extra script that defines this var, then sources my script.

#!/usr/bin/env bash

#set -o xtrace
set -e

###############################################################
# This is a wrapper for the arduino-ide.AppImage
#
# Important:
#   This script must be copied to the same directory as the AppImage.
#   Only one *.AppImage (with the x flag set) may exist in this directory.

###############################################################
# Configuration options:
#
# PORTABLE_PATH / DEFAULT_PORTABLE_PATH:
# PORTABLE_PATH defines the Arduino variant/instance/installation to use.
# It can be specified as an absolute path or relative to the APPDIR.
# If PORTABLE_PATH does not exist, you will be asked whether to create it.
# If PORTABLE_PATH was not defined before starting this script, DEFAULT_PORTABLE_PATH will be used.
DEFAULT_PORTABLE_PATH="portable"
#PORTABLE_PATH="portable"

# SKETCHBOOK:
# If your sketchbook is on a USB stick, SKETCHBOOK should be set to the
# relative path within the directory; otherwise, it should be left undefined.
SKETCHBOOK="Portables/Arduino/portable/Sketchbook"

# Run the app in the background (with nohup)
DOBACKGROUND="${DOBACKGROUND-y}"

# Uncomment if your AppImage doesn't work without --no-sandbox.
# See Note 1 (below) for information on customizing your AppImage for sandbox support.
#NO_SANDBOX=--no-sandbox

# End of Configuration options
###############################################################

###############################################################
# Get Path of this script
###############################################################
APPDIR="$(dirname -- "$(readlink -f -- "${0}")" )"
cd ${APPDIR}

MOUNT_POINT=$(df --output=target "${APPDIR}" | tail -n1)
REL_PATH="${APPDIR#$MOUNT_POINT/}"  # whithout leading slash

###############################################################
# Determine exe
###############################################################
EXE=$(find . -maxdepth 1 -executable -name "*.AppImage")
EXE_CNT=$(find . -maxdepth 1 -executable -name "*.AppImage" | grep -c ".AppImage")
if [ ${EXE_CNT} -ne 1 ]; then 
  read -p "Invaid # of AppImages found: ${EXE_CNT}"
  exit
fi

###############################################################
# PORTABLE_PATH / DEFAULT_PORTABLE_PATH -> NEW_HOME
###############################################################
USED_PORTABLE_PATH="${PORTABLE_PATH-${DEFAULT_PORTABLE_PATH}}"
if [ ! "${USED_PORTABLE_PATH%%/*}" ]; then
  # PORTABLE_PATH is an absolute path
  NEW_HOME="${USED_PORTABLE_PATH}"
 else
  # PORTABLE_PATH is a relative path
  NEW_HOME="${APPDIR}/${USED_PORTABLE_PATH}"
fi

###############################################################
# NEW_HOME exist ?
###############################################################
CreateYaml()
 {
  if [ ! -z "${SKETCHBOOK-x}" ]; then
    echo "directories:" >"${yaml}"
    echo "    user: ${MOUNT_POINT}/${SKETCHBOOK}" >>"${yaml}"
  fi
 }

yaml="${NEW_HOME}/.arduinoIDE/arduino-cli.yaml"
if [ ! -d "${NEW_HOME}" ]; then
  if GetYn "Do you wish to create \"${NEW_HOME}\"? "; then
    exit
  fi
  # Create NEW_HOME (& create yaml if needed)
  mkdir "${NEW_HOME}"
  CreateYaml
 else
  # Adjust path to Sketchbook inside ${yaml}
  if [ ! -e "${yaml}" ]; then # yaml does not exist
    CreateYaml
  fi
  if [ ! -z "${SKETCHBOOK}" ]; then	# SKETCHBOOK set
    t=$(grep "user: ${MOUNT_POINT}/${SKETCHBOOK}" "${yaml}")
    if [ -z "${t}" ]; then				# user does not point to current mount-point
      sed -i -e "s;user: .*;user: ${MOUNT_POINT}/${SKETCHBOOK};g" "${yaml}"
    fi
  fi
fi

###############################################################
# Start Arduiino
###############################################################
if [ "${DOBACKGROUND}" != "y" ]; then
  HOME="${NEW_HOME}" "${EXE}" ${NO_SANDBOX}
 else
  HOME="${NEW_HOME}" nohup "${EXE}" ${NO_SANDBOX} >"nohup.out" 2>&1 &
  sleep 5
fi

###############################################################
# Get User Input Yes or No return 0 if user enters no
###############################################################
GetYn()
 {
  while true; do
    read -p "$1" yn
    case $yn in
      [Yy]* ) return 1;;
      [Nn]* ) return 0;;
      * ) echo "Please answer yes or no.";;
    esac
  done
 }

###############################################################
# Note 1
#
# Currently all AppImage (started under Ubuntu 24.04) terminate with error:
# "The SUID sandbox helper binary was found, but is not configured correctly"
# The problem seams to be, that the files extracted from an AppImage to a
# temporary dir will lose the suid bit!
# This leads to the failure of chrome-sandbox (from within AppImage)
#
# Modify AppImage to use chrome-sandbox (in opt) of local system:
#
# cd <to dir containing the AppImage>
# EXE=$(find . -maxdepth 1 -executable -name "*.AppImage")
# mkdir t; cd t
# Download appimagetool from https://github.com/AppImage/appimagetool/releases
# Set TOOL to its full path
# TOOL=$(find / -executable -iname "appimagetool*.AppImage")
# ${EXE} --appimage-extract
# cd squashfs-root/
# #Optional: sudo cp usr/share/icons/hicolor/512x512/apps/arduino-ide.png /usr/share/icons/hicolor/512x512/apps/arduino-ide.png
# rm chrome-sandbox
# ln -s $(sudo find /opt -name "chrome-sandbox") chrome-sandbox
# cd ..
# ARCH=x86_64 ${TOOL} squashfs-root # Adjust ARCH as nessesary
# rm -r squashfs-root/
# move the new AppImage to desired dir
# cd ..; rm -r t
###############################################################

1 Like

That should indeed be the sketchbook directory.

Not quite; preferences would be what you called settings. As far as I know it's a directory where stuff is remembered like the last sketches and the board that that sketch is compiled for; it contains something more but I'm definitely not sure of what exactly.


There should be one more, the cache where compiled files are cached so not every file will be compiled over and over again. On Windows it is C:\Users\yourUsername\AppData\Local\arduino and contains the directories cores and sketches. It might be beneficial to also have that on the removable media but I have no idea how to configure its path.


I'm an occasional Linux user. I will need to analyse your script and possibly consult man pages and bash tutorials to figure out what is all going on :wink:

~/.config/arduino-ide
I use "Preferences ?", because there is a file called so.

Instead/Additionaly of useing "HOME=..." you may use under Windows:
set USERPROFILE=...
set APPDATA=...

What environment var is used by the arduing ide may be evaluated from their github source repro.

If you need help in understanding the script simply ask (via email)

~/.config/arduino-ide
I use "Preferences ?", because there is a file called so.

Instead/Additionaly of useing "HOME=..." you may use under Windows:
set USERPROFILE=...
set APPDATA=...

What environment var is used by the arduing ide may be evaluated from their github source repro.

If you need help in understanding the script simply ask (via email)