From 4e4b9b3d252a93a5308f24997b3f5217ccd0901e Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 17 Feb 2024 07:38:40 -0600 Subject: [PATCH] Add Run Commands With Specific Rails Version as a Rails TIL --- README.md | 3 +- ...un-commands-with-specific-rails-version.md | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 rails/run-commands-with-specific-rails-version.md diff --git a/README.md b/README.md index ce11890..f80a467 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1368 TILs and counting..._ +_1369 TILs and counting..._ --- @@ -899,6 +899,7 @@ _1368 TILs and counting..._ - [Rollback A Specific Migration Out Of Order](rails/rollback-a-specific-migration-out-of-order.md) - [Rounding Numbers With Precision](rails/rounding-numbers-with-precision.md) - [Run A Rake Task Programmatically](rails/run-a-rake-task-programmatically.md) +- [Run Commands With Specific Rails Version](rails/run-commands-with-specific-rails-version.md) - [Run Some Code Whenever Rails Console Starts](rails/run-some-code-whenever-rails-console-starts.md) - [Schedule Sidekiq Jobs Out Into The Future](rails/schedule-sidekiq-jobs-out-into-the-future.md) - [Secure Passwords With Rails And Bcrypt](rails/secure-passwords-with-rails-and-bcrypt.md) diff --git a/rails/run-commands-with-specific-rails-version.md b/rails/run-commands-with-specific-rails-version.md new file mode 100644 index 0000000..ea66b88 --- /dev/null +++ b/rails/run-commands-with-specific-rails-version.md @@ -0,0 +1,30 @@ +# Run Commands With Specific Rails Version + +You can have multiple versions of a gem like `rails` installed with `gem`. +However, when you go to run a rails command, your system will default to using +the latest version that you have installed. + +So doing a version check will show that version to currently be `7.1.3` and +running something like `rails new` will set up a new Rails 7.1.3 app. + +```bash +$ rails --version +Rails 7.1.3 + +$ rails new my_app +``` + +If you want to use a Rails version besides the latest you have installed for +whatever command, you can use a `gem` convention which is to put `__` +right after the gem name. + +Let's try this for Rails 6.1.3: + +```bash +$ rails _6.1.3_ --version +Rails 6.1.3 + +$ rails _6.1.3_ new my_app +``` + +[source](https://stackoverflow.com/a/452458/535590)