Terminal.| command | Description |
|---|---|
| cd directory | change directories |
| cd ~ | go back to my home directory |
| cd .. | go back up one directory |
| ls | a listing of what’s in the current directory |
| Tab key | auto complete name |
| ls -la | give us a list of all the things in the directory including hidden configuration files |
| echo ‘hello’ | return a value |
| echo $SHELL | return the value of a special constant that’s set up called shell |
| which | show where a program is located |
| which echo | show where echo is located : /bin/echo |
cat.bash_profile |
output the contents of file .bash_profile |
| cmd K | clear terminal screen |
Note:
shell called bash.Pathecho $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
This is my current path, the places that it will look for commands and the order that it will look for them. So first it will look in user/bin to see if I have echo in there. If I don’t, then next it will look inside /bin to see if it is there. Then we’re looking user/sbin, sbin, /opt/X11/bin, and finally in this path here.
\bin, that’s where it found echo, so it didn’t find it in user\bin, he found it in just bin. This is very important.
$PATH does not include the path where that’s located. It’s not going to look anywhere else. It’s going to look in these places, that are in this list /usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin, and then, it’s going to give up and say, sorry, I can’t find it..bash_profile and .profile are basically the same things. .bash_profileis just for the bash shell, whereas .profile is for all shells. I typically tend to use bash_profile just to make sure that it’s clear that these are the instructions I want to use with bash. You don’t want to have both unless you really are certain about what you are doing, because they can conflict with each other.
nano eg. use nano .bash_profile to open up .bash_profile.bash_profile:
PS1="David$ "
alias ll="ls -lahG"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"PS1 will change default prompt shhhappy$ to be David$alias alias ll to be equal to ls -lahG It’s the same thing as ls-la that I’ve been typing with h and G just to make it look a little prettier.export PATH lets $PATH be equal to /usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH The directory we first want to look in to see if we have anything installed is /usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin. i.e Before looking in the default places $PATH, check a few of my custom folders/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin first.user/local is where we’re going to be storing things and that’s a very common way to do it so that all of your programs that you install will all be installed in your user local folder. They’ll be kept there and separate from everything else.the .profile and .bash_profile get run whenever a new terminal window opens. You can close terminal and open again or just type source ~/.bash_profile.
gcc. ###Install commandline tool for Xcode this step is necessary.Homebre, and we will install Homebrew next because it will make it easier for us to install the other components of the software that we’ll need.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew -v
Approximated result
Homebrew 0.9.5
brew doctor
If it asks you to run brew update, do so.
If it returns:
“No such file or directory - /usr/local/Cellar”
You should type and enter:
cd sudo mkdir /usr/local/Cellar
Enter your login password and press enter (you won't be able to see it)
If it returns:
Error: No such file or directory - /Library/Developer/CommandLineTools/usr/bin/clang
You should update Xcode CommandLineTools (https://developer.apple.com/downloads/index.action#)
brew update
There’s three main versions of Ruby which you’re likely to come across. These are recent versions.
Tiger) through through Mac OS 10.8(Mountain Lion).Even better, and more popular in the Ruby and Rails development community is to use a manager for Ruby:
what’s especially great about them is they let you install multiple versions of Ruby and switch between them and even have projects that are on different versions.
over the last year, rbenv has become the more popular choice in the developmentcommunity.
RVM is short for Ruby Version Manager. RVM makes it easy to install different versions of Ruby on your computer and manage them as well
\curl -L https://get.rvm.io | bash -s stable
2.Close your terminal and then re-open it. Now, lets see if RVM was loaded properly:
type rvm | head -n 1
3.Now install Ruby with:
rvm use ruby --install --default
ruby -v
rbenv, type this in your terminalbrew install RBENV
this will install Ruby Env for you
brew install ruby-build
Ruby env..bash_profile, which tells rbenv to initialize itselfeval "$(rbenv init -)"
Ruby 2.1.5)ruby -v
assume the current version is 1.8.7
5.Install the newest version of Ruby
rbenv install 2.1.5
Ruby will be installled to /user/shhhappy/.rbenv/versions/2.1.5
6.check current ruby verion
ruby -v
the result is still 1.8.7
rbenv rehash
rbenv rehash is a very important command. Any time that we install a new version of Ruby, or, when we install any kind of a Gem that also provides commands in the command line.
8.check ruby verion again
ruby -v
RBENV global 2.1.5
-in addition to global, we ca use local, which would be for a certain project. - local would then set that for that project or shell, which means to just write now in the currently running window. Just switch there for a minute. Don’t switch globally. Don’t switch my project. Just quickly switch over, while I do some things, into this new version.
ruby -v
rbenv versions
RubyGem or just called Gem for short, is simply ruby code that has been packaged up for easy distribution using the package manager.Rails is itself a Gem
gem -v
used to find out if you have RubyGems installed.
which gem
gives a clue about how that got installed. You can see that it’s in this ./rbenv folder, inside shems. And that lets me know that during the process of installing RBN and Ruby, it also installed RubyGems at the same time.
gem list
show the gems that are currently installed.
gem update --system
That will go out to the RubyGems server. Look and see if we have the latest version and update it if necessary.
gem --help
that will give you more information about how you can go about using RubyGems. a good place to look for help and guidance.
bundler.
Bundler is a tool that helps your rails application to load the right ruby gemsbundler was added in rails 3, to manage the gems that each application needs.gem install bundler
his will tell the Ruby Gem’s package manager to go to the Ruby Gem’s website to look for the latest version of Bundler, to download it and then install it.
Bundler allows us to run commands from the command line, too
Note: you need to type rehash whenever there’s something that’s going to have a command line command that needs to be available.
rbenv rehash
In this case, it will make bundler avaliable
bundler -v
tells the version of Bundler
which bundler
tell me where bundler is located,and you can see that it’s located in that rbenv folder. The rehash command is what put it there
gem install rails
But before we hit return there are a couple of options that we could provide here. You may have noticed when it installed bundler that it also installed some documentation so whenever we install ruby gems its going to want to install that documentation as well. That documentation just sits quietly on our hard drive taking up space and almost no one ever refers to it. And for Rails, that documentation is quite extensive. So we can skip the download and processing of that documentation by passing it in the --no-ri --no-rdoc and it will not generate either the ri or rdoc documentation for this.
gem install rails --no-ri --no-rdoc
It speeds up the installation process and it doesn’t take up space on your hard drive with documentation that you’re never going to look at.
But we may not want the latest version. It depends on when you’re watching this training. Now this training will work with all versions of Rails 4.0. If we get to version 5.0 of Rails, it may still work but if you need to specify, if you need to go back and pick a previous version.
gem install rails --no-ri --no-rdoc --version 4.0.0
rbenv rehash
will make rails avaliable
rails -v
which rails
will check Rails version and location - which rails will show us that it added that shim to the rbenv folder
So we type list gem list and we’ll see a list of all of the different gems that it installed. You can see that Rails has lots of dependencies, other gems that it depends on.
actionmailer (4.1.7, 4.1.4)
actionpack (4.1.7, 4.1.4)
actionview (4.1.7, 4.1.4)
activemodel (4.1.7, 4.1.4)
activerecord (4.1.7, 4.1.4)
activesupport (4.1.7, 4.1.4)
is the core parts of Ruby on Rails
When developing web applications, we’re going to use a database to store information
To check and see if you have MySQL installed,
mysql --version
brew install mysql one nice thing is that when it goes out to the server, it knows what your processor is and it knows what your operating system version are.
\\To connect to server:
mysql -uroot (or mysql -u root)
\\ launchctl means launch control
\\To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
\\Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
\\Or, if you don't want/need launchctl, you can just run:
mysql.server start
\\other options
mysql.server stop
mysql.server restart
mysql.server status
if error occurs
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
solution: check system preference -> mysql, the status was STOP. Just restart it and it works fine on my mac now.
To check version of MySQL and where it is installed:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.21, for osx10.8 (x86_64) using EditLine wrapper
$ which mysql
/usr/local/bin/mysql
To connect to server:
mysql -u root
Note:If you had previously installed this and secured it with a root password you might also need to provide the -p option which would let you then type your password.
To secure MySQL’s root password
mysqladmin -u root password
Note: If you had a previous password you could provide the -p option.
mysqladmin -u root password -p
It would ask for your old password first, and then your new password.
mysql -u root -p
input exit to exit SQL
gem install mysql2
Note:
mysql used to be the main gem that we would use for Ruby on Rails but there is a new and improved version. And the way that you get it ismysql2. It’s actually a completely separate version created by someone else but it’s the version that we should be using not just mysql but mysql2.building native extensions, because it actually builds code for us that’s in something like c so that it’s able to run really, really fast.All of the back-end pieces installed: - Ruby - Ruby Gems - Rails - MySQL
we need to have a web server when we’re in production. - When we put this out there on the internet for people to access, they’re going to come with their browser. They’re going to type in a URL, and it’s going to connect to our web server. To return a request to them. And that web server will then in turn talk to our Rails application to figure out what it ought to return.
the same thing is to be true in development. We’re going to follow the exact same process, we’re going to have our browser connecting to a web server, talking to our Rails application.
the main choices of web server:
Passenger
mod_rails,Apache module, which allows Apache to talk to Rails so that we have an interface between Apache and Rails. There’s definitely a great combination and I would say that probably the vast majority of rails driven websites out there in production are using Apache 2 with Passengerlighter weight: they don’t have all of the features, they don’t necessarily have the same robustness(A characteristic describing a model’s, test’s or system’s ability to effectively perform while its variables or assumptions are altered.) that Apache and Engine X have, but they do have more speed.Need a good text editor which you can use for writing your code
syntax for Ruby, Rails, HTML, CSS, and JavaScript, and can color it appropriately.in termimal
1.get $PATH
echo $PATH
symbolic linksymbolic link
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
/usr/local/bin/sublto this location to ’/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl`subl filename
subl folderName
to open up an entire folder to view a whole set of files and folders at the same time nad view them as a project
Now sublime has lots of features. You can go to the sublime text website to find documentation and find out how to get the most out of it
IDE stands for Integrated Development Environment