Resolving the Could not find package /laravel/laravel Error
When running composer create-project --prefer-dist laravel/laravel project, you might encounter a cryptic error message: "Could not find package /laravel/laravel with stability stable." This isn't usually a sign that the Laravel installer itself is broken, but rather a misconfiguration in your Composer environment or a conflict between how the installer script expects to run versus how it's being invoked.
The root cause often lies in how Composer resolves packages. The composer create-project command attempts to download and install the Laravel installer script directly into your project before scaffolding the application. If you see the error about missing stability, it usually means Composer cannot locate the laravel/laravel package in its repository with the defined stable stability level. This can happen if your composer.json or composer.lock files are present but corrupted, or if your Composer configuration explicitly restricts allowed packages or stabilities in a way that excludes Laravel.
To verify this, inspect your current Composer configuration. Running composer config repositories should return an empty list unless you have manually defined custom repositories. If you have added a repository that points to an invalid source or restricted stability levels globally, it will block the standard installation of laravel/laravel. You can reset these settings by running:
composer config --global repositories.json ""
composer config --global allow-plugins.* yes
Additionally, ensure your global Composer version is up to date. Older versions might lack support for newer package metadata or stability flags required by recent Laravel releases. Update with:
composer self-update
Once updated and configuration cleaned, retry the original command:
composer create-project --prefer-dist laravel/laravel project
If you still face issues, consider bypassing the create-project command entirely and installing the standalone Laravel installer script. This method is often more reliable across different environments, including shared hosting or containers where global Composer repositories might be locked down.
First, ensure the PHP binary can execute scripts and that your system has sufficient disk space. Then, move to the directory where the Laravel installer resides (often found in ~/.config/composer/vendor/laravel/installer if installed globally via a previous command). From there, you can invoke the installer directly:
php /path/to/laravel/installer.php new project
This approach bypasses Composer's package resolution for the initial scaffold and instead downloads Laravel's bootstrap files directly. While this works, it often results in a flood of suggestions after installation, such as installing symfony/psr-http-message-bridge or psy/psysh. These are soft dependencies that enhance functionality but aren't strictly required for the application to run. You can suppress these prompts by passing the --no-interaction flag:
php /path/to/laravel/installer.php new project --no-interaction
Alternatively, you can install Laravel via Git, which provides a clean slate without pre-existing lock files or configuration conflicts:
git clone https://github.com/laravel/laravel.git project
cd project
composer install
This method ensures that all dependencies are resolved fresh against the latest Composer repository state. It's particularly useful when your global Composer environment has become inconsistent due to frequent updates or plugin installations.
If you're working in a LAMP stack on Linux Mint, ensure that your Apache or Nginx server is configured to serve PHP 8.x correctly and that open_basedir restrictions aren't blocking Composer from writing to its cache directory. Check your php.ini for any upload_max_filesize or memory_limit constraints that might interfere with large package downloads.
In summary, the error stems from a mismatch between expected package availability and actual repository access. By resetting Composer configuration, updating tools, or switching to direct installer invocation, you can reliably scaffold a new Laravel project regardless of your underlying system setup.