Skip to content
scala: command not found

scala: command not found

DodaTech 2 min read

The “scala: command not found” error means your shell cannot locate the scala runner or scalac compiler binaries needed to compile Scala code.

What It Means

Scala provides two main command-line tools: scala for running compiled classes and scripts, and scalac for compiling .scala source files into JVM bytecode. Both are distributed with the Scala compiler installation. When neither is found in your PATH, the shell returns “command not found.”

Why It Happens

  • Scala is not installed on your system.
  • Coursier (the recommended Launcher) installed Scala but did not update your PATH.
  • SDKMAN installed Scala but the terminal session wasn’t reloaded.
  • The Scala binary directory is not in your PATH environment variable.
  • You installed Scala via a package manager that puts binaries in a non-standard location.
  • The installation was interrupted or incomplete.

How to Fix It

1. Install Scala via Coursier (recommended)

Coursier is the standard Scala installer. It manages both the JVM and Scala versions:

# Install Coursier
curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs
chmod +x cs
./cs setup

# This installs Scala, sbt, and updates ~/.profile
# Then reload your shell:
source ~/.profile

# Verify
scala -version
# Output: Scala code runner version 3.5.0

2. Install Scala via SDKMAN

# Install SDKMAN
curl -s https://get.sdkman.io | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

# Install Scala
sdk install scala

# Verify
scala -version

3. Install Scala via sbt launcher

If you already have sbt, it can download Scala for you:

# sbt automatically downloads the Scala version specified in build.sbt
echo 'scalaVersion := "3.5.0"' > build.sbt
sbt compile

4. Manually add Scala to your PATH

If Scala is installed but not found:

# For Coursier installation
export PATH="$PATH:$HOME/.local/share/coursier/bin"
# For SDKMAN
export PATH="$PATH:$HOME/.sdkman/candidates/scala/current/bin"

# Add the appropriate line to ~/.bashrc or ~/.zshrc

5. Verify Java is installed

Scala runs on the JVM. Ensure JDK 11+ is available:

java -version
# If not found, install a JDK:
# Via Coursier: cs install java
# Via SDKMAN:   sdk install java
What’s the difference between scala and scalac?
scalac compiles .scala files to .class bytecode. scala runs compiled programs and also executes .scala scripts directly. In Scala 3, scalac is also available as scala compile.
Do I need both Scala and sbt?
No — sbt includes its own Scala compiler distribution. If you use sbt exclusively, you don’t need the standalone scala command. The standalone compiler is useful for scripting and quick experiments.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro