← 返回命令列表

Linux command

rails-new 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Create a new Rails application

rails new [app_name]

Create an application with PostgreSQL

rails new [app_name] --database=postgresql

Create an application with MySQL

rails new [app_name] --database=mysql

Create an API-only application

rails new [app_name] --api

Create an application without Action Mailer

rails new [app_name] --skip-action-mailer

Create an application with a specific Rails version

rails _[version]_ new [app_name]

Create an application in the current directory

rails new .

说明

rails new creates a new Ruby on Rails application with the standard directory structure, configuration files, and dependencies. It generates everything needed to start developing a web application immediately. The command creates directories for models, views, controllers, tests, and configurations. It initializes a Gemfile with common dependencies, sets up database configuration, and optionally initializes a git repository. Rails applications follow convention over configuration. The generated structure establishes conventions that other Rails commands and the framework expect, enabling features like automatic routing and model discovery.

参数

--database, -d _adapter_
Preconfigure for selected database (sqlite3, mysql, postgresql, oracle, sqlserver, etc.)
--api
Create an API-only application (smaller middleware stack, no views)
--skip-git
Skip git init and .gitignore generation
--skip-docker
Skip Dockerfile and related files
--skip-action-mailer
Skip Action Mailer files
--skip-action-mailbox
Skip Action Mailbox gem
--skip-action-text
Skip Action Text gem
--skip-active-record
Skip Active Record files (for non-database apps)
--skip-active-storage
Skip Active Storage files
--skip-action-cable
Skip Action Cable files
--skip-asset-pipeline
Skip asset pipeline
--skip-javascript
Skip JavaScript files
--skip-hotwire
Skip Hotwire integration
--skip-jbuilder
Skip jbuilder gem
--skip-test
Skip test files
--skip-bundle
Don't run bundle install
--css _processor_
Choose CSS processor (tailwind, bootstrap, bulma, postcss, sass)
--javascript _bundler_
Choose JavaScript bundler (importmap, bun, webpack, esbuild, rollup)
--template, -m _path_
Apply an application template from a path or URL
--force, -f
Overwrite files that already exist
--pretend, -p
Run but do not make any changes
--quiet, -q
Suppress status output

FAQ

What is the rails-new command used for?

rails new creates a new Ruby on Rails application with the standard directory structure, configuration files, and dependencies. It generates everything needed to start developing a web application immediately. The command creates directories for models, views, controllers, tests, and configurations. It initializes a Gemfile with common dependencies, sets up database configuration, and optionally initializes a git repository. Rails applications follow convention over configuration. The generated structure establishes conventions that other Rails commands and the framework expect, enabling features like automatic routing and model discovery.

How do I run a basic rails-new example?

Run `rails new [app_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --database, -d _adapter_ do in rails-new?

Preconfigure for selected database (sqlite3, mysql, postgresql, oracle, sqlserver, etc.)