Skip to main content

Install TypeScript on AlmaLinux: A Practical Project Setup

Laptop with TypeScript code, a blue TS tile and a Linux penguin illustrating a project setup

To install TypeScript on AlmaLinux, start with a supported Node.js runtime and add the compiler to your project as a development dependency. This keeps the compiler version with the code and makes local and CI builds easier to reproduce. You do not need a global compiler or root privileges for the project setup.

This walkthrough creates a small command-line project. An existing application may already have its own framework, package manager and module settings; follow those conventions rather than replacing its configuration with a tutorial.

1. Check AlmaLinux, Node.js and npm

cat /etc/os-release
node --version
npm --version
command -v node
command -v npm

If Node.js is missing, inspect the packages available from your approved repositories:

dnf info nodejs npm

On a machine where these packages provide the supported version your project needs, an administrator can install them with:

sudo dnf install nodejs npm

Review the proposed packages before accepting. Repository choices vary across AlmaLinux releases. Do not assume that a module-stream command copied from an older release applies to every system, or reset an existing stream without reviewing the applications that use it.

Check the Node.js release schedule and your dependencies’ runtime requirements. As reviewed in October 2026, Node.js 22 and 24 are LTS lines, while Node.js 20 has reached upstream end of life. Distribution maintenance policies can differ, so assess the package source as well as the major version.

2. Create a project-local TypeScript installation

Run the following as your ordinary development user in a new directory:

mkdir typescript-demo
cd typescript-demo
npm init -y
npm install --save-dev --save-exact typescript
npx tsc --version

The compiler is recorded in devDependencies. The exact version and lockfile capture the chosen dependency state. Review package lifecycle scripts and dependency sources under your normal supply-chain policy. Avoid using sudo npm install to solve a project ownership problem.

3. Add a small, explicit configuration

Create tsconfig.json with this minimal configuration. It uses a simple CommonJS output so the first example does not depend on an application framework:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "CommonJS",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "noEmitOnError": true
  },
  "include": ["src/**/*.ts"]
}

Create a src directory and save this as src/main.ts:

const message: string = "Hello from TypeScript on AlmaLinux";
console.log(message);

Compile the project and execute its generated JavaScript:

npx tsc -p tsconfig.json
node dist/main.js

Expected output is the greeting above. Specifying a project reads its configuration; passing individual source filenames to the compiler is a different invocation and does not apply the same project-file workflow.

4. Add build and type-check scripts

In package.json, add or merge the following scripts while retaining the other fields:

"scripts": {
  "build": "tsc -p tsconfig.json",
  "check": "tsc -p tsconfig.json --noEmit",
  "start": "node dist/main.js"
}
npm run check
npm run build
npm start

A type-checking command should fail the build when the compiler reports errors. For example, assigning a number to the string variable is a useful temporary learning exercise. Restore the correct code afterward. Do not suppress compiler errors simply to make a pipeline green.

5. Reproduce the installation in CI

Commit the source, package.json, package-lock.json and configuration. Exclude generated dependency folders such as node_modules/ from source control. In a clean checkout with the agreed Node.js and npm versions, run:

npm ci
npm run check
npm run build

npm ci requires a lockfile consistent with the package manifest and replaces an existing dependency directory. It does not update the lockfile for you. Build jobs need development dependencies because that is where this compiler is installed.

Troubleshoot common setup problems

  • tsc is not found: confirm the local dependency is installed and use an npm script or npx tsc.
  • Permission denied: check project ownership and package-cache configuration instead of making the directory world-writable.
  • Unexpected ESM/CommonJS errors: align the package type, compiler module setting and runtime. Existing ESM projects need an appropriate configuration, not a blind copy of this sample.
  • npm ci fails: inspect manifest/lockfile differences and the npm version used to create the lockfile.

Frequently asked questions

Does TypeScript validate API responses at runtime?

No. Static types are not a substitute for validating untrusted inputs. Add runtime validation where data enters the application.

How do I update or remove TypeScript?

Upgrade deliberately in a branch, review the compiler’s release notes, and run application tests. To remove the local dependency, use npm uninstall --save-dev typescript and review the manifest and lockfile changes.

References and related reading

A practical guide for your next challenge. A fresh perspective for everyday life. Discover both through Nandan’s latest articles.

Post Comments

Leave a Reply

Your email address will not be published. Required fields are marked *