How To Install TypeScript on Manjaro

TypeScript has become an essential tool for modern web development, offering static typing and enhanced developer experience on top of JavaScript. If you’re running Manjaro Linux and want to harness the power of TypeScript, you’ve come to the right place. This comprehensive guide walks you through multiple installation methods, from using npm to leveraging Manjaro’s native package manager.
Whether you’re building enterprise applications or personal projects, TypeScript provides type safety that catches errors before runtime. Manjaro’s Arch-based foundation offers flexibility in how you install and manage TypeScript. You’ll discover the most efficient approaches tailored to your workflow and project requirements.
This tutorial covers everything from prerequisites to advanced configuration. You’ll learn four distinct installation methods, verify your setup, and troubleshoot common issues. By the end, you’ll have a fully functional TypeScript environment ready for development.
Prerequisites and System Requirements
Before installing TypeScript on your Manjaro system, ensure you meet the necessary requirements. Your system should run any Manjaro edition—KDE Plasma, XFCE, or GNOME—with at least 500MB of free disk space. Terminal access with sudo privileges is essential for most installation methods.
Check your system is up to date by running:
sudo pacman -Syu
This command synchronizes your package database and updates all installed packages. A current system prevents compatibility issues during TypeScript installation.
Verify your system architecture:
uname -m
Most modern systems display x86_64 for 64-bit architecture. Check available disk space with:
df -h
Basic familiarity with command-line operations helps you follow along smoothly. Understanding package management concepts makes the installation process more intuitive. You should know how to open a terminal, navigate directories, and edit configuration files using text editors like nano or vim.
Method 1: Installing TypeScript via npm (Recommended)
The npm approach provides the most up-to-date TypeScript version and aligns with JavaScript ecosystem standards. This method offers flexibility and integrates seamlessly with modern development workflows.
Installing Node.js and npm
TypeScript distributes primarily through npm, the Node.js package manager. You must install Node.js before proceeding with TypeScript installation.
Update your package database:
sudo pacman -Sy
Install Node.js and npm together:
sudo pacman -S nodejs npm
This command downloads and installs both packages from Manjaro’s official repositories. The installation process takes a few minutes depending on your internet connection speed.
Verify Node.js installed correctly:
node -v
You should see output like v20.9.0 or similar. Check npm installation:
npm -v
The version number confirms npm is ready. Typical output shows 10.1.0 or newer.
Alternative Approach: Node Version Manager
NVM provides superior flexibility for managing multiple Node.js versions. This approach benefits developers working across different projects with varying Node.js requirements.
Install NVM from the AUR using yay:
yay -S nvm
If you prefer pamac:
pamac install nvm
Initialize NVM in your current shell session:
source /usr/share/nvm/init-nvm.sh
Add this line to your ~/.bashrc file for automatic initialization:
echo 'source /usr/share/nvm/init-nvm.sh' >> ~/.bashrc
Reload your shell configuration:
source ~/.bashrc
Install the latest Node.js version:
nvm install node
NVM downloads and configures Node.js automatically. You can install specific versions like nvm install 18 or nvm install 20. Switch between versions using nvm use 18 or nvm use 20.
Installing TypeScript Globally
Global installation makes the TypeScript compiler available system-wide. This approach suits developers who use TypeScript across multiple projects without version-specific requirements.
Execute the global installation command:
npm install -g typescript
The -g flag instructs npm to install TypeScript globally rather than in a project-specific location. You’ll see progress indicators as npm downloads dependencies and configures the package.
During installation, npm places TypeScript in /usr/lib/node_modules/typescript. The compiler executable becomes accessible as tsc from any directory.
Verify your installation:
tsc -v
Alternative verification command:
tsc --version
Both commands display the installed TypeScript version, typically showing Version 5.3.3 or newer. This confirms successful installation and proper PATH configuration.
Permission Considerations
Most npm global installations on Manjaro work without sudo when Node.js was installed via pacman. If you encounter permission errors, avoid using sudo with npm. Instead, configure npm to use a directory your user owns.
Installing TypeScript Locally (Project-Specific)
Local installation provides better version control and project isolation. This method ensures different projects can use different TypeScript versions without conflicts.
Create a new project directory:
mkdir ~/typescript-project
cd ~/typescript-project
Initialize a new npm project:
npm init -y
The -y flag accepts all default values, creating a package.json file instantly. This file manages your project’s dependencies and configuration.
Install TypeScript as a development dependency:
npm install --save-dev typescript
The --save-dev flag adds TypeScript to the devDependencies section of package.json. Development dependencies don’t get included when others install your package as a library.
Verify installation by checking package.json:
cat package.json
You’ll see TypeScript listed under devDependencies with its version number.
Use the local TypeScript compiler with npx:
npx tsc --version
The npx command executes binaries from your project’s node_modules folder. This approach guarantees you’re using the project-specific TypeScript version rather than a global installation.
Local installations excel in team environments. Your package.json ensures all developers use identical TypeScript versions, preventing “works on my machine” scenarios.
Method 2: Installing TypeScript via Pacman
Manjaro’s native package manager offers a straightforward TypeScript installation path. This method integrates TypeScript with your system’s package management infrastructure.
Installing from Official Repositories
Search for TypeScript in the repositories:
pacman -Ss typescript
This command lists available packages matching “typescript.” You’ll see the main typescript package along with related tools.
Install TypeScript using pacman:
sudo pacman -S typescript
Pacman handles dependency resolution automatically, downloading and configuring everything needed for TypeScript to function. The installation completes faster than npm since packages come pre-compiled for Arch-based systems.
Verify the installation:
tsc --version
The version from official repositories might lag behind the latest npm release. Manjaro packages undergo testing for stability, which introduces a slight delay compared to upstream releases.
Understanding Package Differences
The npm and pacman installation methods differ in several important ways. Understanding these distinctions helps you choose the appropriate approach for your needs.
Version Currency
npm installations typically provide newer versions. The npm registry updates immediately when TypeScript releases new versions. Manjaro repositories update after packages pass testing and review processes.
System Integration
Pacman installations integrate with Manjaro’s package management ecosystem. System-wide updates via sudo pacman -Syu include TypeScript. npm installations require separate update commands like npm update -g typescript.
Dependency Management
Pacman tracks dependencies at the system level. Removing packages automatically handles orphaned dependencies with sudo pacman -Rs typescript. npm manages dependencies within the Node.js ecosystem, maintaining separate dependency trees.
Update Frequency
npm packages update frequently, sometimes weekly during active development periods. Pacman packages update based on Manjaro’s release cycle, typically providing major version updates and critical patches.
Choose pacman when you prioritize system-wide consistency and stable, tested releases. Opt for npm when you need bleeding-edge features and frequent updates.
Remove TypeScript installed via pacman:
sudo pacman -R typescript
Add the -s flag to remove unused dependencies:
sudo pacman -Rs typescript
Method 3: Alternative Installation Methods
Beyond npm and pacman, Manjaro supports additional installation approaches. These alternatives cater to specific use cases and preferences.
Installing via AUR (Arch User Repository)
The Arch User Repository extends Manjaro’s package selection with community-maintained builds. AUR provides access to development versions and alternative TypeScript packages.
Understanding AUR
AUR contains build scripts (PKGBUILDs) rather than pre-compiled packages. AUR helpers automate downloading, building, and installing these packages. Popular AUR helpers include yay and pamac.
Install TypeScript using yay:
yay -S typescript
Using pamac:
pamac build typescript
Both commands search the AUR, download the PKGBUILD, compile the package, and install it. The process resembles pacman but includes compilation steps.
Development Version
Install the git development version:
yay -S typescript-git
This package builds TypeScript from the latest source code. Development versions include unreleased features but may contain bugs. Use development builds for testing upcoming features or contributing to TypeScript development.
Safety Considerations
Always review PKGBUILDs before installation. View the build script:
yay -Gp typescript
Examine the commands and sources to ensure they’re legitimate. The AUR community flags malicious packages, but vigilance remains important.
Update AUR packages regularly:
yay -Sua
This command updates all AUR packages on your system.
Installing via Snap
Snap packages provide containerized applications with bundled dependencies. Snap installations run in isolated environments, preventing conflicts with system packages.
Enable Snap support on Manjaro:
sudo pacman -S snapd
Enable and start the snapd service:
sudo systemctl enable --now snapd.socket
Create a symbolic link for classic snap support:
sudo ln -s /var/lib/snapd/snap /snap
Restart your system or log out and back in for PATH changes to take effect.
Install TypeScript as a snap:
sudo snap install typescript
Snap installations provide clean removal and easy updates. However, the isolated environment may complicate integration with other development tools.
Update snaps automatically or manually:
sudo snap refresh typescript
Remove TypeScript snap:
sudo snap remove typescript
Snap suits scenarios where you need isolated environments or simplified distribution. The containerization prevents TypeScript from interfering with system-level packages.
Verifying and Testing TypeScript Installation
Confirmation of successful installation prevents frustration during development. Thorough verification catches configuration issues early.
Verification Commands
Check the compiler version:
tsc --version
View comprehensive help documentation:
tsc --help
The help output displays all available compiler flags and options. Familiarize yourself with common flags like --target, --module, and --outDir.
Locate the TypeScript compiler executable:
which tsc
This command shows the full path to the tsc binary. Typical locations include /usr/bin/tsc for pacman installations or /usr/lib/node_modules/.bin/tsc for npm global installations.
For npm installations, verify the global package:
npm list -g typescript
This displays the installed version within npm’s global package tree.
Creating Your First TypeScript File
Practical testing validates your installation works correctly. Creating and compiling a simple TypeScript file confirms everything functions as expected.
Create a test directory:
mkdir ~/typescript-test
cd ~/typescript-test
Create a TypeScript source file:
nano hello.ts
Add this sample code:
console.log("Hello, Manjaro!");
const greeting: string = "TypeScript installed successfully!";
console.log(greeting);
function add(a: number, b: number): number {
return a + b;
}
console.log("2 + 3 =", add(2, 3));
Save and exit nano (Ctrl+O, Enter, Ctrl+X).
Compile the TypeScript file:
tsc hello.ts
TypeScript creates hello.js in the same directory. The compiler transpiles your TypeScript code into JavaScript that Node.js can execute.
Examine the generated JavaScript:
cat hello.js
Notice how TypeScript type annotations disappear in the compiled output. JavaScript runtimes don’t understand TypeScript syntax, so compilation removes type information.
Execute the compiled JavaScript:
node hello.js
You should see:
Hello, Manjaro!
TypeScript installed successfully!
2 + 3 = 5
This output confirms your TypeScript toolchain works end-to-end. You’ve successfully written TypeScript, compiled it, and executed the resulting JavaScript.
Configuring TypeScript with tsconfig.json
Configuration files streamline TypeScript compilation for complex projects. The tsconfig.json file centralizes compiler options, eliminating repetitive command-line flags.
Initializing TypeScript Configuration
Generate a default configuration:
tsc --init
This command creates tsconfig.json in your current directory with extensive comments explaining each option. The default configuration provides sensible starting points for most projects.
View the configuration file:
cat tsconfig.json
The file uses JSON format with commented-out options you can enable. TypeScript’s compiler reads this configuration automatically when you run tsc without file arguments.
Essential Configuration Options
Understanding key configuration options helps you tailor TypeScript to your project’s needs.
target
Specifies the ECMAScript version for compiled JavaScript. Options include ES5, ES6/ES2015, ES2020, and ESNext. Modern Node.js supports ES2020 or newer:
"target": "ES2020"
module
Defines the module system for output JavaScript. Common values include commonjs (for Node.js), es6/es2015, and esnext:
"module": "commonjs"
outDir
Specifies where compiled JavaScript files are written. Separating source and output directories keeps projects organized:
"outDir": "./dist"
rootDir
Indicates where TypeScript source files reside:
"rootDir": "./src"
strict
Enables all strict type-checking options. Strict mode catches more potential bugs but requires more explicit typing:
"strict": true
esModuleInterop
Improves compatibility between CommonJS and ES modules:
"esModuleInterop": true
Sample Configuration
Here’s a practical configuration for Node.js projects:
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
This configuration compiles TypeScript files from src/ into JavaScript in dist/, using strict type checking and modern JavaScript features.
Create your source directory:
mkdir src
Move your TypeScript files into src/:
mv hello.ts src/
Compile using the configuration:
tsc
Without file arguments, tsc uses tsconfig.json automatically. Compiled files appear in dist/ as specified in outDir.
Troubleshooting Common Issues
Even straightforward installations sometimes encounter obstacles. Understanding common problems and their solutions saves debugging time.
“tsc: command not found” Error
This error indicates the TypeScript compiler isn’t in your system PATH. Several factors cause this issue.
PATH Configuration
For npm global installations, ensure npm’s bin directory is in your PATH. Check your current PATH:
echo $PATH
Get npm’s prefix:
npm config get prefix
The output typically shows /usr or ~/.npm-global. The bin directory is <prefix>/bin.
Add npm’s bin directory to PATH temporarily:
export PATH=$PATH:$(npm config get prefix)/bin
Test tsc again. If it works, make this change permanent.
For bash, add to ~/.bashrc:
echo 'export PATH=$PATH:'$(npm config get prefix)'/bin' >> ~/.bashrc
For zsh, add to ~/.zshrc:
echo 'export PATH=$PATH:'$(npm config get prefix)'/bin' >> ~/.zshrc
Reload your shell configuration:
source ~/.bashrc
Alternative Solution
Use npx to run TypeScript without PATH modifications:
npx tsc --version
This approach works for both global and local installations.
Permission Errors
Permission issues typically arise when npm tries to write to system directories.
Avoiding sudo with npm
Never install npm packages globally with sudo. This creates permission problems and security risks. Instead, configure npm to use a directory your user owns.
Create a directory for global packages:
mkdir ~/.npm-global
Configure npm to use this directory:
npm config set prefix '~/.npm-global'
Add the new bin directory to PATH:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Reinstall TypeScript without sudo:
npm install -g typescript
Node Version Conflicts
Multiple Node.js versions sometimes create conflicts. NVM resolves these issues by isolating each version.
List installed Node.js versions:
nvm list
Switch to a specific version:
nvm use 20
Set a default version:
nvm alias default 20
Package Lock Issues
Corrupted package-lock.json files cause installation failures. Delete and regenerate the lock file:
rm package-lock.json
npm install
Cache Problems
Corrupted npm cache sometimes prevents installations. Clear the cache:
npm cache clean --force
Reinstall TypeScript after clearing the cache.
Best Practices for TypeScript on Manjaro
Adopting best practices ensures a smooth TypeScript development experience on Manjaro.
Keep Software Updated
Regular updates provide security patches and new features. Update npm packages:
npm update -g typescript
Update system packages:
sudo pacman -Syu
Use Version Managers
NVM provides flexibility for managing Node.js versions. Different projects often require different Node.js versions. NVM makes switching between versions effortless.
Prefer Project-Specific Installations
Local installations prevent version conflicts. Your package.json documents exact dependency versions, ensuring reproducible builds across development environments.
Version Control Integration
Include package.json and package-lock.json in version control. Exclude node_modules/ by adding it to .gitignore. This approach lets teammates install identical dependencies with npm install.
IDE Integration
Modern editors provide excellent TypeScript support. Visual Studio Code includes built-in TypeScript integration. Install TypeScript extensions for Vim:
vim +PluginInstall +qall
For Emacs, use Tide mode. Proper IDE integration enables features like autocomplete, inline error detection, and automated refactoring.
Regular System Maintenance
Keep your Manjaro system current:
sudo pacman -Syu
Clean package cache periodically:
sudo pacman -Sc
Documentation Reference
The official TypeScript handbook provides comprehensive documentation. Bookmark the handbook for reference during development. The documentation includes examples, best practices, and detailed explanations of language features.
Congratulations! You have successfully installed TypeScript. Thanks for using this tutorial for installing TypeScript open source programming language on your Manjaro Linux system. For additional help or useful information, we recommend you check the official TypeScript website.