-
Update system packages:
sudo apt update && sudo apt upgrade -y -
Install the essential tools:
sudo apt install -y curl git unzip software-properties-common -
Add the Emacs PPA:
sudo add-apt-repository -y ppa:ubuntuhandbook1/emacs -
Update with new PPA:
sudo apt update -
Install Emacs:
sudo apt install -y emacs-pgtk -
Verify installation:
emacs --version
-
Install Java 17 (OpenJDK):
sudo apt install -y openjdk-17-jdk openjdk-17-source -
Verify installation:
java -version -
Set JAVA_HOME persistently:
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-$(dpkg --print-architecture)' >> ~/.bashrcsource ~/.bashrc -
Verify that the environment variable is setup:
echo $JAVA_HOMEls $JAVA_HOME/bin/java
-
Check the hardware architecture (whether x86_64 or aarch64 (ARM 64)):
uname -a -
Download the appropriate version of the tool keeping the correct architecture in mind:
-
Download command for x86_64:
curl -fL "https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-linux.gz" | gzip -d > cs -
Download command for aarch64:
curl -fL "https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-linux.gz" | gzip -d > cs
-
-
Make
csexecutable:chmod u+x cs -
Run Scala setup (installs cs, scala-cli, sbt, scalafmt, etc.):
./cs setup -y -
Source updated PATH:
source ~/.profile -
Verify installation:
cs versionsbt --version -
Perform cleanup:
rm ./cs
-
Install Metals:
cs install metals -
Verify installation:
metals --versionwhich metalsThe last command should print:
~/.local/share/coursier/bin/metals
-
Create the Emacs config (if it doesn't exist):
mkdir ~/.emacs.d -
Create the config file:
touch ~/.emacs.d/init.el -
Downalod the
~/.emacs.d/init.elfile using the link:https://gist.githubusercontent.com/nimeshneema/9060117c2d94c8912176a5b74a127383/raw/b8ee41dd8d2992abb695e80f9922d0332ce19ad5/init.el
-
On first launch, Emacs connects to the MELPA and downloads all packages. This may take 1-3 minutes. You'll see activity in the Emacs minibuffer. When it settles, quit emacs and re-launch.
-
Verify packages are installed:
Press
M-x, typepackage-list-packages, and pressRET. This will list all the packages.Type
/senterinstalledpressRETto see the installed packages.Type
/senterdependencypressRETto see the dependencies. -
Confirm the following packages all appear labelled either as "installed" or "dependency":
scala-modelsp-modelsp-metalslsp-uicompanyflycheckyasnippetsbt-modedap-mode
-
Download a minimal sample Scala project using the link:
https://github.com/nimeshneema/scala-test-project/archive/main.zipOnce downloaded, unzip and move the
scala-test-projectto home directory.
-
Run the following:
cd ~/scala-test-projectsbt compileFirst run downloads sbt + Scala + deps — may take several minutes
Expected output:
[success] -
Open in Emacs
cd ~/scala-test-projectemacs src/main/scala/example/Main.scala
-
Test each feature once the build import has completed:
-
Syntax Highlighting
Keywords, strings, comments should each be in distinct colors.
-
Error Diagnostics
Type
val x: Int = "oops"on a new line, save (C-x C-s), wait a few seconds. An error should appear (underline/highlight + sideline message). Undo withC-/. -
Auto-Completion
Type
fleet.on a new line insidemain. A popup should appear showingfilter,map,head,length, etc. Navigate with arrows, accept with RET, cancel withC-g. -
Hover Documentation
Cursor on
filter→C-c C-d(orM-x lsp-ui-doc-show). Type signature and docs should appear. -
Go to Definition
Cursor on
checkGearin the call →M-.(Meta-period). Jumps to the definition.M-,jumps back. -
Find References
Cursor on
Aircraft→M-x lsp-find-references RET. Lists all usages. -
Type at Point
Cursor on
retractableGear→C-c C-t. Should showList[Aircraft]. -
Code Actions
C-c C-aat various positions to see available actions. -
Rename Symbol
Cursor on
fleet→C-c C-r→ typeaircraftFleet→ RET. All occurrences rename. Undo withC-/repeated. -
Format Buffer
C-c C-freformats per Scalafmt rules. -
Organize Imports
Add
import scala.collection.mutable.ListBufferat top (unused).C-c C-oshould remove it. -
Code Lenses
Look above
def mainfor clickable annotation like▶ run. -
Build Import on Change
Open
build.sbt(C-x C-f build.sbt), add a comment, save. Should prompt to re-import. -
sbt Mode
M-x sbt-start RET→ typecompilein the sbt shell →runto execute. Switch back withC-x b Main.scala RET. -
Metals Doctor
M-x lsp-metals-doctor-run RET. Diagnostic report should appear. -