First, use the command yum to update the original program on this server. Such a program is called a package.
It is a software management mechanism in Linux. It plays the same role as homebrew for MacOS. By using the yum command, you can manage the versions of programs under the control of yum and update them in a batch.
A set of programs with a certain role / function under LinuxOS. It can be called software or library. In Linux OS, a set of programs with a certain role / function is called a package.
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y update
Install various other packages required for environment construction
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install git make gcc-c++ patch libyaml-devel libffi-devel libicu-devel zlib-devel readline-devel libxml2-devel libxslt-devel ImageMagick ImageMagick-devel openssl-devel libcurl libcurl-devel curl
-y is an option for the yum command. Commands such as yum install ask Yes or No, like [y / n], is it really okay to install? In this case, press the Y key and then the Enter key, and the installation will be performed normally. However, there are times when you are new to the game or accidentally press a key other than the Y key. Here, in order to install reliably, let's set -y as an option in advance so that all questions are automatically answered with Yes and execute the command.
If you accidentally forget the option, the following question will be asked. Press the Y key and then the Enter key to complete the installation.
Total download capacity: 120 M
Is this ok [y/d/N]:
Install Node.js to run JavaScript on EC2.
Node.js A JavaScript package that runs on the server side. It will be used when compressing CSS and images in the work for future deployment.
[ec2-user@ip-172-31-25-189 ~]$ sudo curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash -
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install nodejs
If a confirmation screen appears here as well, press the "y" → return key to confirm.
This completes the Node.js installation.
Install rbenv and ruby-build. I used it when building the Mac environment, but I will explain it briefly again. rbenv and ruby-build are tools that are used in combination when managing Ruby versions. These need to be installed before installing Ruby. ruby-build is a plugin for rbenv that allows you to install different versions of Ruby (such as 2.0.0) with ruby-build. You can switch the ruby version by using rbenv.
#Install rbenv
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
#Pass through
[ec2-user@ip-172-31-25-189 ~]$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
#Description for calling rbenv
[ec2-user@ip-172-31-25-189 ~]$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
#.bash_Load profile
[ec2-user@ip-172-31-25-189 ~]$ source .bash_profile
#ruby-install build
[ec2-user@ip-172-31-25-189 ~]$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
#Do rehash
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash
The first command is cloning rbenv from git. The second and third commands are the commands you need to pass through the path. Passing the path means making the application callable from any directory. Then, with the fourth command, the set path is read. The fifth command is cloning ruby-build from git. The last command is the command you need to be able to use gem commands in your version of Ruby.
This completes the installation of rbenv and ruby-build.
Please change it according to the version of Ruby to be installed and the version of Ruby used in your application.
[ec2-user@ip-172-31-25-189 ~]$ rbenv install 2.5.1
[ec2-user@ip-172-31-25-189 ~]$ rbenv global 2.5.1
[ec2-user@ip-172-31-25-189 ~]$ rbenv rehash #Do rehash
[ec2-user@ip-172-31-25-189 ~]$ ruby -v #Check version
The first command installs the 2.5.1 version of Ruby. Installing Ruby takes time. It seems to stop with the message "Installing ruby-2.5.1 ..." appearing in the terminal, but let's just wait. The second command determines the version of Ruby to use within your EC2 instance. The third line is rehashing again. Finally, type the ruby -v command to check the version.
Environment construction in EC2 instance is completed
There are several types of databases in a nutshell. The types are shown below.
・ Hierarchical database ・ Network database ・ Relational database The most used of these is the relational database. You can organize and manage information in the form of an Excel table. And the software that manages this relational database is called a relational database management system (RDBMS).
One of the representative RDBMSs is MySQL.
MySQL MySQL is an RDBMS developed and provided by Oracle. You can create, edit, delete, etc. the database. It is released as open source software and anyone can use it free of charge. It can be used in combination with Ruby on Rails, and this curriculum consistently uses MySQL.
Oracle MySQL introduction page MySQL official page
Rails and all other necessary software are installed in one EC2 instance. MySQL is one of them. The one labeled "database server" in the figure above corresponds to MySQL. Software like MySQL manages the database, so it is sometimes called that way.
If you are using Amazon Linux, you can install MySQL from the yum command.
[ec2-user@ip-172-31-25-189 ~]$ sudo yum -y install mysql56-server mysql56-devel mysql56
This means installing version 5.6 of MySQL.
Use the service command to start MySQL. This is included in Amazon Linux and CentOS, and is a tool that allows you to start the installed software all at once.
[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld start
Note that it's mysqld, not mysql. The "d" is an acronym for "daemon" which means "server" in Linux terminology.
Check if it can be started
[ec2-user@ip-172-31-25-189 ~]$ sudo service mysqld status
mysqld (pid 15692) is running...
If "running" is displayed, MySQL startup is successful.
By default, MySQL installed with yum can be accessed by the user root, but no password is set.
Therefore, let's set a password with the following command. For the part of'password you want to set', for example, if you set the character string password0000, write'password0000'. In many cases, passwords starting with 0 will not be read, so avoid them! (For example, '0331higuchi')
[ec2-user@ip-172-31-25-189 ~]$ sudo /usr/libexec/mysql56/mysqladmin -u root password 'Please change this to the password you want to set and then execute the command.'
Remember this password as you will use it later when accessing it from Rails.
At this time, a warning "Warning: Using a password on the command line interface can be insecure." May appear, but you can safely ignore it here.
Check if the set password can be used
[ec2-user@ip-172-31-25-189 ~]$ mysql -u root -p
You will be prompted to enter the password: Enter password :. Enter the password you set earlier and press Enter. If the following is displayed, the MySQL settings are complete.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Let's get out of MySQL with Ctrl + c for the next task.
Recommended Posts