Skip to content
railway ssh --session has a different PATH to railway ssh
frank-embleton
OP

7 months ago

I’m seeing inconsistent environment behaviour between railway ssh and railway ssh --session

Railway CLI: 4.40.0

railway ssh

✓ Connected to interactive shell                                                                                                                                                                                               root@bd024a39ad51:/app# node Welcome to Node.js v22.22.2. 
Type ".help" for more information. 
>  
(To exit, press Ctrl+C again or Ctrl+D or type .exit) >  root@bd024a39ad51:/app# echo $PATH /app/node_modules/.bin:/app/node_modules/.bin:/mise/shims:/mise/shims:/mise/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

railway ssh --session

root@bd024a39ad51:/app# node
-bash: node: command not found
root@bd024a39ad51:/app# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I have tried adding a preDeployCommand to symlink the mise shims to a location that is in PATH, but that doesn't work eitherln -sf /mise/shims/* /usr/local/bin/

What is the recommended way to place npm and node in PATH when using the Tmux session?

$20 Bounty

3 Replies

Railway
BOT

7 months ago

The --session flag starts a tmux process which spawns a new login shell that does not inherit the environment variables (including the modified PATH with /mise/shims) that railway ssh injects into the direct interactive session. This is a known behavioral difference where tmux resets the shell environment. As a workaround, you can source the PATH in your shell profile by adding export PATH="/mise/shims:/app/node_modules/.bin:$PATH" to /root/.bashrc in your Dockerfile so that tmux's login shell picks it up.


Status changed to Awaiting User Response Railway • 7 months ago


Status changed to Awaiting Railway Response Railway • 7 months ago


Railway

The `--session` flag starts a tmux process which spawns a new login shell that does not inherit the environment variables (including the modified PATH with `/mise/shims`) that `railway ssh` injects into the direct interactive session. This is a known behavioral difference where tmux resets the shell environment. As a workaround, you can source the PATH in your shell profile by adding `export PATH="/mise/shims:/app/node_modules/.bin:$PATH"` to `/root/.bashrc` in your Dockerfile so that tmux's login shell picks it up.

frank-embleton
OP

7 months ago

I am using Railpack not Dockerfile. If this is "a known behavioral difference" then why is it not documented?


Status changed to Open Railway • 7 months ago


duetmain

a month ago

AI-assisted answer; I checked Railway’s current docs and tested the PATH/profile shell logic locally, not on your service.

For Railpack, you do not need to switch to Docker. Your two PATH outputs show that the session shell is missing /mise/shims and /app/node_modules/.bin. First, in the existing railway ssh --session pane, run:

export PATH="/mise/shims:/app/node_modules/.bin:$PATH"
hash -r
command -v node npm
node --version
npm --version

The preDeployCommand symlink approach cannot persist: Railway runs pre-deploy in a separate container and discards its filesystem changes (https://docs.railway.com/deployments/pre-deploy-command).

For new login shells in the root container shown in your logs, if /etc/profile sources /etc/profile.d/*.sh, you can create a dedicated profile file in the RUNNING container:

printf '%s\n' 'export PATH="/mise/shims:/app/node_modules/.bin:$PATH"' > /etc/profile.d/railpack-tools.sh

That file will not update an already-open pane, so use the export above there. Container filesystem edits also disappear on redeploy. To recreate the file each deployment while keeping Railpack, put that printf in your application start wrapper before exec-ing your existing app command, rather than in pre-deploy. This assumes the start process runs as root and that later shell startup files do not overwrite PATH.

If the immediate export still fails, the next useful check is whether /mise/shims/node and /mise/shims/npm exist in that same deployment instance. Please share only the command output, with any secrets removed.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...