wheels get environment
Overview
The wheels get environment command displays the current environment setting for your Wheels application. It automatically detects which environment your application is configured to run in (development, staging, production, etc.) and shows where this configuration is coming from.
Command Syntax
wheels get environmentAlias
wheels get envParameters
This command takes no parameters.
Basic Usage
Display Current Environment
wheels get environmentThis will output something like:
Current Environment:
development
Configured in: .env file (WHEELS_ENV)How It Works
Detection Priority
The command checks for environment configuration in the following order of precedence:
.envfile - Looks forWHEELS_ENVvariable first, thenEnvironmentvariableSystem environment variable - Checks for
WHEELS_ENVfirst, thenEnvironmentsystem variableDefault - Falls back to
developmentif no configuration is found
The first valid configuration found is used and reported, along with which specific variable name was found.
Configuration Sources
1. .env File
The command first looks for a WHEELS_ENV variable in your application's .env file:
# .env file - Primary variable
WHEELS_ENV=production
DATABASE_HOST=localhostIf WHEELS_ENV is not found, it then checks for Environment:
# .env file - Alternative variable
Environment=staging
DATABASE_HOST=localhostThe regex pattern used ensures it correctly reads the value while ignoring:
Comments after the value (anything after
#)Trailing whitespace
Lines that are commented out
2. System Environment Variable
If not found in .env, it checks for system-level environment variables in the same order:
# Linux/Mac - Primary variable
export WHEELS_ENV=staging
# Windows - Primary variable
set WHEELS_ENV=staging
# Or using the alternative variable
export Environment=production3. Default Value
If no configuration is found anywhere, it defaults to development.
Variable Priority
The command checks for two different variable names in this specific order:
WHEELS_ENVin.envfileEnvironmentin.envfileWHEELS_ENVsystem environment variableEnvironmentsystem environment variableDefault to
development
Output Examples
Configured with WHEELS_ENV in .env
Current Environment:
production
Configured in: .env file (WHEELS_ENV)Configured with Environment in .env
Current Environment:
staging
Configured in: .env file (Environment)Configured via System Variable (WHEELS_ENV)
Current Environment:
staging
Configured in: System environment variable (WHEELS_ENV)Configured via System Variable (Environment)
Current Environment:
production
Configured in: System environment variable (Environment)Using Default
Current Environment:
development
Configured in: Using defaultCommon Use Cases
Verify Environment Before Deployment
# Check environment before starting server
wheels get environment
commandbox server startTroubleshooting Configuration Issues
# Verify which configuration source and variable is being used
wheels get environment
# Check each source manually
cat .env | grep -E "WHEELS_ENV|Environment"
echo $WHEELS_ENV
echo $EnvironmentCI/CD Pipeline Verification
# In deployment script
wheels get environment
if [ $? -eq 0 ]; then
    echo "Environment configured successfully"
fiSupporting Legacy Systems
# If migrating from a system that uses "Environment" variable
# Both will work without changes:
# Old: Environment=production
# New: WHEELS_ENV=production
wheels get environmentError Handling
The command will show an error if:
It's not run from a Wheels application directory
There's an error reading configuration files
File permissions prevent reading configuration
Not a Wheels Application
Error: This command must be run from a Wheels application directoryRead Error
Error reading environment: [specific error message]Best Practices
Use WHEELS_ENV - Prefer
WHEELS_ENVoverEnvironmentfor clarity and consistencyConsistent Configuration - Use one primary method for setting environment across your team
Environment-Specific Files - Consider using
.env.production,.env.developmentfiles with the merge commandDon't Commit Production Settings - Keep production
.envfiles out of version controlDocument Your Setup - Document which configuration method and variable name your team uses
Verify Before Deployment - Always run this command to verify environment before deploying
Environment Precedence
Understanding precedence is important when multiple configurations exist:
.env file - WHEELS_ENV (highest priority)
    ↓
.env file - Environment
    ↓
System variable - WHEELS_ENV
    ↓
System variable - Environment
    ↓
Default: development (lowest priority)If both WHEELS_ENV and Environment are set in .env, only WHEELS_ENV will be used.
Migration Guide
If you're migrating from a system that uses different environment variable names:
From "Environment" to "WHEELS_ENV"
# Old configuration
Environment=production
# New configuration (both work)
WHEELS_ENV=production
# The command will detect either one
wheels get environmentGradual Migration
You can migrate gradually since the command checks both:
Leave existing
Environmentvariables in placeStart using
WHEELS_ENVfor new deploymentsThe command will prefer
WHEELS_ENVwhen both exist
Integration with Other Commands
This command works well with other Wheels CLI commands:
# Check environment, then run migrations
wheels get environment
wheels db migrate
# Verify environment before running tests
wheels get environment
wheels test
# Check environment, then start server
wheels get environment
commandbox server startTips
The command must be run from your Wheels application root directory
Environment values are case-sensitive (
development≠Development)Comments in
.envfiles are properly ignored using#Whitespace around values is automatically trimmed
The command clearly shows which variable name was found
WHEELS_ENVtakes precedence overEnvironmentwhen both exist
Troubleshooting
Environment Not Changing
If changing environment variables doesn't seem to work:
Run
wheels get environmentto see which source and variable is being usedRemember
.envfile takes precedence over system variablesRemember
WHEELS_ENVtakes precedence overEnvironmentRestart your CommandBox server after changes
Check for typos in variable names
Variable Priority Issues
If the wrong environment is being detected:
Check if both
WHEELS_ENVandEnvironmentare setRemember
WHEELS_ENVhas higher priorityUse the output to see exactly which variable is being read
Permission Errors
If you get permission errors:
Ensure you have read access to
.envfilesCheck that you're in the correct directory
Verify file ownership and permissions
Unexpected Default
If you're getting the default development when you expect a different value:
Check for typos in configuration files (it's
WHEELS_ENVnotWHEEL_ENV)Ensure
.envfile is in the application rootVerify system environment variables are properly exported
Check that values don't have quotes unless intended
Last updated
Was this helpful?

