Hướng dẫn cài install rails win 10
RVM viết tắt của từ Ruby Version Manager nghĩa là quản lý version Ruby, giúp chúng ta có thể cài nhiều bản ruby cùng 1 lúc Trên ubutun ta có thể cài theo hướng dẫn : https://github.com/rvm/ubuntu_rvm Chạy rvm version để kiểm tra chúng ta đã cài đặt thành công Sau khi cài xong rvm ta cài ruby:
Sử dụng RVM để cài sẽ có trường hợp bạn bật terminal lên ruby nó k nhận : ruby -v nó ra not found Giải quyết bằng cách : https://askubuntu.com/questions/624610/ruby-command-not-recognized-after-installing-it-with-rvm Solution 1: Using ~/.bashrc file Open your ~/.bashrc file and put these two lines (or last one) there. Load RVM into a shell session as a function
Solution 2: Make the regular shell session as login shell Or you can turn on your virtual terminal’s preference to consider the shell as Login Shell. The settings can be found in
Với Rails chúng ta cần JavaScript Runtime để compile asset pipeline của Rails, trước khi cài Rails các bạn cần cài thêm Nodejs và Yarn
check xem đã cài thành công chưa bằng cách
Giờ chúng ta có thể cài đặt Rails Sau khi cài đặt hoàn tất check Rails version Cài đặt MysqlSử dụng MySQL Cài đặt theo hướng dẫn : https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/ Cài đặt gitTạo tài khoản trên https://github.com/ Cài đặt git :
Config git:
[email protected]: email tài khoản github bạn đăng ký Vậy ta đã cài đặt git và config thành công rồi. bạn có thể kéo code về sử dụng https : bằng cách git clone
1 Nếu sử dụng https mỗi lần đẩy code lên github bạn sẽ phải nhập user name và password. để giảm thao tác đó chúng ta sẽ sử dụng ssh Connect máy mình vs github thông qua ssh tham khảo thêm tại : https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
Sau đó copy kết quả của dòng lệnh trên, mở github vào link setting ssh https://github.com/settings/keys . Tạo mới ssh key, điền tên và paste kết quả dòng lệnh vừa rồi Vậy là đã xong. check bạn đã kết nối thành công bằng cách
2 Nếu hiện Hi excid3! You’ve successfully authenticated, but GitHub does not provide shell access. là đã kết nối github bằng ssh thành công rồi đó Giờ ta có thể thực hiện git clone bằng ssh :
Cài đặt sublime textSublime Text khác với các IDE khác ở đặc điểm nhẹ, linh hoạt trong tùy biến và cung cấp nhiều tính năng rất tiện lợi khi lập trình. Mình suggest các bạn dùng phần mềm này để code We're going to use the Windows Subsystem for Linux (WSL) to accomplish this. This allows you to install a Linux distribution natively on Windows without a virtual machine. Ruby on Rails will always be deployed to a Linux server, so it's best for us to use the same for development. Windows allows you to run various Linux operating systems inside of Windows similar to a virtual machine, but natively implemented. We'll use this to install Ruby and run our Rails apps. You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11. Open Powershell and run:
Reboot your computer to finish the installation. Once initial setup is finished, you will be prompted to create a username and password for your Ubuntu install. You can search for "Ubuntu" in the Windows Start Menu anytime to open the Ubuntu terminal. Congrats! You now have Ubuntu installed on Windows with WSL. You'll use this to run your Rails server and other processes for development. The first step is to install dependencies for compiling Ruby. Open your Terminal and run the following commands to install them.
Next we're going to be installing Ruby using a version manager called ASDF. The reason we use ASDF over rbenv, rvm or others is that ASDF can manage other languages like Node.js too. Installing
6 is a simple two step process. First you install
6, and then add it to your shell:
Then we can install ASDF plugins for each language we want to use. For Rails, we can install Ruby and Node.js for our frontend Javascript.
Choose the version of Ruby you want to install: To install Ruby and set the default version, we'll run the following commands:
Confirm the default Ruby version matches the version you just installed.
Then we can install the latest Node.js for handling Javascript in our Rails apps:
Configuring GitWe'll be using Git for our version control system so we're going to set it up to match our Github account. If you don't already have a Github account, make sure to register. It will come in handy for the future. Replace my name and email address in the following steps with the ones you used for your Github account.
The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.
Once you've done this, you can check and see if it worked:
You should get a message like this:
0 Choose the version of Rails you want to install:
1 Now that you've installed Rails, you can run the
8 command to make sure you have everything installed correctly:
2 If you get a different result for some reason, it means your environment may not be setup properly. For PostgreSQL, we're going to add a new repository to easily install a recent version of Postgres.
3 You'll need to start postgresql each time you load your WSL environment. The postgres installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace
9 with your username.
4 Let's create your first Rails application on Windows!
5 You can now visit http://localhost:3000 to view your new website! Getting an "Access Denied" error? If you received an error that said
0 then you need to edit the
1 file to match the database username and password. Editing CodeInstall VS Code on Windows and install the WSL extension. This will allow you to edit code in Windows but run commands and extensions in WSL. Read more about Developing in WSL. That's it! Let us know in the comments below if you run into any issues or have any other protips to share! |