Deploying with the CLI
The Railway CLI provides deployment capabilities for both local development workflows and automated CI/CD pipelines.
Quick deploy
The simplest way to deploy is with railway up:
# Link to your project first (if not already linked)
railway link
# Deploy the current directory
railway upThis command scans, compresses, and uploads your app's files to Railway. You'll see real-time deployment logs in your terminal.
Railway will build your code using Railpack or your Dockerfile, then deploy it.
Deployment modes
Attached mode (default)
By default, railway up streams build and deployment logs to your terminal:
railway upThis is useful for watching the build process and catching errors immediately.
Detached mode
Use -d or --detach to return immediately after uploading:
railway up -dThe deployment continues in the background. Check status in the dashboard or with railway logs.
CI mode
Use -c or --ci to stream only build logs and exit when the build completes:
railway up --ciThis is ideal for CI/CD pipelines where you want to see the build output but don't need to wait for deployment logs. Use --json to output logs in JSON format (also implies CI mode).
Targeting services and environments
Deploy to a specific service
If your project has multiple services, the CLI will prompt you to choose. You can also specify directly:
railway up --service my-apiDeploy to a specific environment
railway up --environment stagingDeploy to a specific project
Use -p or --project to deploy to a project without linking:
railway up --project <project-id> --environment productionNote: When using --project, the --environment flag is required.
CI/CD integration
Using project tokens
For automated deployments, use a Project Token instead of interactive login. Project tokens are scoped to a specific environment and can only perform deployment-related actions.
RAILWAY_TOKEN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX railway upSome actions you can perform with a project token:
- Deploying code -
railway up - Redeploying a deployment -
railway redeploy - Viewing build and deployment logs -
railway logs
GitHub actions
Railway makes deployment status available to GitHub, so you can trigger actions after deployments complete.
Post-deployment actions
Use the deployment_status event to run commands after Railway deploys your app:
name: Post-Deployment Actions
on:
deployment_status:
states: [success]
jobs:
post-deploy:
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- name: Run post-deploy actions
if: github.event.deployment.environment == 'production'
run: |
echo "Production deployment succeeded"
# Add your post-deploy commands hereSee the GitHub Actions Post-Deploy guide for more details.
PR environments with GitHub actions
Create Railway environments automatically for pull requests:
name: Manage PR environments (Railway)
on:
pull_request:
types: [opened, closed]
env:
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
LINK_PROJECT_ID: "your-project-id"
DUPLICATE_FROM_ID: "environment-to-duplicate"
jobs:
pr_opened:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
container: ghcr.io/railwayapp/cli:latest
steps:
- name: Link to project
run: railway link --project ${{ env.LINK_PROJECT_ID }} --environment ${{ env.DUPLICATE_FROM_ID }}
- name: Create Railway Environment for PR
run: railway environment new pr-${{ github.event.pull_request.number }} --copy ${{ env.DUPLICATE_FROM_ID }}
pr_closed:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
container: ghcr.io/railwayapp/cli:latest
steps:
- name: Link to project
run: railway link --project ${{ env.LINK_PROJECT_ID }} --environment ${{ env.DUPLICATE_FROM_ID }}
- name: Delete Railway Environment for PR
run: railway environment delete pr-${{ github.event.pull_request.number }} || trueNote: If you are using a workspace project, ensure the token is scoped to your account, not a specific workspace.
See the GitHub Actions PR Environment guide for the complete setup.
Redeploying
Redeploy the current deployment without uploading new code:
railway redeployThis is useful for:
- Applying environment variable changes
- Restarting a crashed service
- Triggering a fresh build with the same code
Deploying a specific path
You can specify a path to deploy:
railway up ./backendBy default, Railway uses your project root as the archive base. Use --path-as-root to use the specified path as the archive root instead:
railway up ./backend --path-as-rootWhen running railway up from a subdirectory without a path argument, Railway still deploys from the project root. To deploy only a specific directory permanently, configure a root directory in your service settings.
Ignoring files
By default, Railway respects your .gitignore file. To include ignored files in your deployment:
railway up --no-gitignoreVerbose output
For debugging deployment issues:
railway up --verboseRelated
- CLI Reference - Complete CLI command documentation
- GitHub Autodeploys - Automatic deployments from GitHub
- GitHub Actions Post-Deploy - Run actions after deployment
- GitHub Actions PR Environment - Create environments for PRs