Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finished first half (section on NVM)

  • Loading branch information...
commit e5853c56fe3b1fcd6948219388aa67506eb2bd59 1 parent c50d896
@croach authored
Showing with 85 additions and 39 deletions.
  1. +85 −39 02.md
View
124 02.md
@@ -133,45 +133,91 @@ installation is going to take a little while, so Im just going to skip
ahead to the end, so you may want to pause this screencast now until
your installation is complete.
-Now that we've got a couple of versions of node installed on our
-system, let's take another look at the output of `nvm ls`. Notice that
-it's now listing our installed versions of Node and the one that we
-installed last is the current version that we are using. You can
-confirm this by typing `node -v` and making sure that the version that
-pops up matches the version listed by `current:` in the `ls`
-output. To switch to another version of node, type `nvm use` followed
-by the version number. Go ahead and do that now, switch over to the
-latest version of node. Now if you do an `nvm ls` you should see
-v0.6.13 listed beside `current:` and doing a `node -v` from the
-command line should display v0.6.13 as well. One thing though, try
-opening up a new shell and typing in `node -v` and see what
-happens. Hmm, doesn't exist huh? Doing an `nvm ls` shows us that we
-have two versions installed but neither is currently being used. You
-could go ahead and do a `nvm use` now, but do you really want to do
-that every time? Most of the time, you'll want the latest version of
-node to be the default right? Well, nvm let's us specify this behavior
-by declaring an alias. Aliases are just human readable names for
-specific versions. So, for example, if you like living on the cutting
-edge and you want to install the latest development version of node,
-you could always keep everything clear by marking the current version
-as 'stable' and the bleeding edge version as 'dev', then you can do
-things like `nvm use dev` or `nvm use stable` to switch between
-versions. Another nice thing about aliases is that they allow us to
-specify a default version of node. Go ahead and type `nvm alias
-default v0.6.13` and then run `nvm ls` again. Notice something new at
-the bottom of the output? The `ls` command lists all of our aliases at
-the bottom of the output. You could also run `nvm alias` to see only
-the list of available aliases as well. Now try opening up a new shell
-and type `node -v`. This time you should the version number of our
-default node version print out to the screen. That should be enough to
-get you started with nvm. The app is fairly simple to understand and
-you should be able to pick up the rest by just looking at the help
-output from `nvm help`. Now I want to move onto the more interesting
-stuff and play around with npm a bit. So let's get that installed and
-see what all it can do for us.
-
-## Node's Package Manager (NPM) If you thought the install for nvm was
-easy, wait til you see the install for npm...
+Now that we have a version of node installed on our system, let's take
+another look at the output of `nvm ls`. Notice that this time it's
+listing our newly installed version of Node. It also lists this
+version as the current version that we are using. You can confirm this
+by typing `node -v` and making sure that a version number, rather than
+an error message, pops up.
+
+What would happen though, if we opened another terminal session? Would
+our system still default to the most recently installed version of
+node or something else? Let's try it out and see what happens. If we
+open a new terminal window and type `node -v` again, this time we're
+greeted with an error message telling us that the 'node' command
+doesn't exist. If we type `nvm ls` we see why this is, we haven't
+selected a node to use as our current node. To do so we use the `use`
+command. So, let's go ahead and select version 0.6.15 as our current
+node. Type `nvm use 0.6.15`. With the `use` command the 'v' prefix is
+optional, though I'll show a reason why you might want to use it in
+just a second. Now if we type `nvm ls` again, we should see that our
+current node version is 0.6.15 and typing `node -v` this time should
+confirm it.
+
+So, `nvm use` is the command we use to switch between all the
+different versions of node we have installed on our system. But how do
+we select one version to always be our default current version? Well
+you do that through the alias command.
+
+nvm's alias command allows us to setup several different names for
+versions we use often, as a way of more easily identifying them. If we
+run `nvm help` we see here that we can create a new alias by typing
+`nvm alias` followed by the alias name and by the version number we
+want to associate with that name. So, for example, if we executed the
+command `nvm alias latest 0.6.15` then from that moment on, we could
+refer to version 0.6.15 as simply 'latest'. So the next time we wanted
+to use that version, we could just type `nvm use latest` and
+voila. Much easier than typing in the version number, and it allows us
+to label specific versions according to which projects we were using
+them for.
+
+One alias in particular though that is treated specially by nvm is the
+'default' alias. nvm will automatically load the version of node
+aliased to 'default' as the current version whenever a new shell
+session is created. So let's go ahead and set our default version now
+by typing `nvm alias default v0.6.15`. Now if we start a new shell
+session and type `node -v` we see that the latest version has already
+been selected for us and typing `nvm ls` will confirm that. Notice
+also that underneath the Current version of node is a list of all of
+our aliases that we've defined. Since we've aliased the lastest
+version of node to default, we probably don't actually need another
+alias for it, so let's go ahead and get rid of the 'latest' alias we
+created earlier by typing `nvm unalias latest` and then type `nvm ls`
+just to confirm that it's been removed.
+
+There's one more thing I want cover before moving onto npm, and that's
+an option that was recently added to nvm that supports tab completion
+in Bash. Adding this feature is extremely simple, it's just a matter
+of sourcing another file upon starting a new shell session like we did
+before for nvm.
+
+So, let's open up our .bashrc file again and go back to where we put
+the few lines of code for sourcing nvm. Right below that we're going
+to place another few lines that will essentially do the same thing as
+before. As you can see here, we will first make sure that the
+bash_completion file exists, and then, if it does, we'll source that
+file.
+
+Let's give it a try. Go ahead and save your changes and exit back out
+to the command line. Then source the .bashrc file to make sure that
+it's added the tab completion to our current session. Then type `nvm
+h` and hit the tab button and it should complete the word help. Let's
+try that again with a version number. Type `nvm use v` then tab and it
+should complete the version 0.6.15 (assuming that you haven't
+installed anymore versions). And, that's tab completion. Not an
+absolute must, but still a feature that makes using nvm much nicer all
+around.
+
+Well, that should be enough to get you started with nvm. The app is
+fairly simple to understand and you should be able to pick up the rest
+by just looking at the help output from `nvm help`. Now I want to move
+onto the more interesting stuff and play around with npm a bit. So
+let's get that installed and see what all it can do for us.
+
+## Node's Package Manager (NPM)
+
+If you thought the install for nvm was easy, wait til you see the
+install for npm...
Did you get all that? No, don't worry, I didn't accidentally edit out
the npm install or anything it's just that npm comes already installed
Please sign in to comment.
Something went wrong with that request. Please try again.